<?php

namespace App\Domains\FiestaFutbolInfantil\Controllers;

use App\Domains\FiestaFutbolInfantil\Requests\UpsertAccommodationVariantsRequest;
use App\Domains\FiestaFutbolInfantil\Resources\AccommodationResource;
use App\Domains\FiestaFutbolInfantil\Services\AccommodationService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class AccommodationController extends Controller
{
    public function __construct(private readonly AccommodationService $accommodationService) {}

    public function index(Request $request): AccommodationResource
    {
        return AccommodationResource::make(
            $this->accommodationService->current($request->user()->tenant()->firstOrFail())
        );
    }

    public function store(UpsertAccommodationVariantsRequest $request): AccommodationResource
    {
        $tenant = $request->user()->tenant()->firstOrFail();

        return AccommodationResource::make(
            $this->accommodationService->upsertMany(
                $tenant,
                $request->validated('variants'),
            )
        );
    }

    public function destroy(Request $request, int $accommodation): Response
    {
        $this->accommodationService->delete(
            $request->user()->tenant()->firstOrFail(),
            $accommodation,
        );

        return response()->noContent();
    }
}
