<?php

namespace DMD\LaLigaApi\Controller;

use DMD\LaLigaApi\Service\League\acceptJoinLeagueRequest\HandleAcceptJoinLeagueRequest;
use DMD\LaLigaApi\Service\League\createLeague\HandleCreateLeague;
use DMD\LaLigaApi\Service\League\declineJoinLeagueRequest\HandleDeclineJoinLeagueRequest;
use DMD\LaLigaApi\Service\League\getAllLeagues\HandleGetAllLeagues;
use DMD\LaLigaApi\Service\League\getLeagueById\HandleGetLeagueById;
use DMD\LaLigaApi\Service\League\newJoinLeagueRequest\HandleNewJoinLeagueRequest;
use DMD\LaLigaApi\Service\League\joinTeam\HandleCaptainRequest;
use DMD\LaLigaApi\Service\League\updateLeague\HandleUpdateLeague;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Routing\Annotation\Route;

class LeagueController extends AbstractController
{
    #[Route('/api/league/create', name: 'app_league', methods: ['POST'])]
    public function createLeague(Request $request, HandleCreateLeague $handleCreateLeague): JsonResponse
    {
        return $handleCreateLeague($request);
    }
    #[Route('/api/league/{$leagueId}', name: 'app_update_league', methods: ['PUT'])]
    public function updateLeague(Request $request, HandleUpdateLeague $handleUpdateLeague, int $leagueId): JsonResponse
    {
        return $handleUpdateLeague($request, $leagueId);
    }

    #[Route('/api/league/{leagueId}/join', name: 'app_join_league', methods: ['PUT'])]
    public function joinLeague(Request $request, HandleNewJoinLeagueRequest $handleJoinLeague, int $leagueId): JsonResponse
    {
        return $handleJoinLeague($request, $leagueId);
    }

    /**
     * @throws TransportExceptionInterface
     */
    #[Route('/api/league/{leagueId}/team/{teamId}', name: 'app_join_team', methods: ['PUT'])]
    public function joinTeam(Request $request, HandleCaptainRequest $handleCaptainRequest, int $leagueId, int $teamId): JsonResponse
    {
        return $handleCaptainRequest($request, $leagueId, $teamId);
    }

    #[Route('/api/league/{leagueId}', name: 'app_get_league', methods: ['GET'])]
    public function getLeagueById(Request $request, HandleGetLeagueById $handleGetLeagueById, int $leagueId): JsonResponse
    {
        return $handleGetLeagueById($request, $leagueId);
    }

    #[Route('/api/public/league', name: 'app_get_all_leagues', methods: ['GET'])]
    public function getAllLeagues(HandleGetAllLeagues $handleGetAllLeagues): JsonResponse
    {
        return $handleGetAllLeagues();
    }

    /**
     * @throws TransportExceptionInterface
     */
    #[Route('api/league/{leagueId}/user/{userId}/accept', name: 'app_accept_join_request', methods: ['GET'])]
    public function acceptJoinRequest(
        Request $request,
        HandleAcceptJoinLeagueRequest $handleAcceptJoinLeagueRequest,
        int $leagueId,
        int $userId
    ): JsonResponse
    {
        return $handleAcceptJoinLeagueRequest($request, $leagueId, $userId);
    }

    #[Route('api/league/{leagueId}/decline/{captainId}', name: 'app_decline_join_request', methods: ['GET'])]
    public function declineJoinRequest(Request $request, HandleDeclineJoinLeagueRequest $handleDeclineJoinRequest, int $leagueId, int $captainId): JsonResponse
    {
        return $handleDeclineJoinRequest($request, $leagueId, $captainId);
    }

}
