<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProviderWorkingDayRequest;
use App\Http\Resources\ProviderWorkingDayResource;
use App\Services\ProviderWorkingDayService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ProviderWorkingDayController extends Controller
{
    public function __construct(
        private readonly ProviderWorkingDayService $service
    ) {}

    public function indexByProviderId($id): JsonResponse
    {
        $workingDays = $this->service->getByProvider($id);

        return $this->successResponse(ProviderWorkingDayResource::collection($workingDays));
    }

    public function store(ProviderWorkingDayRequest $request): JsonResponse
    {
        $workingDay = $this->service->create($request->validated());

        return $this->successResponse(new ProviderWorkingDayResource($workingDay));
    }

    public function destroy($id, Request $request): JsonResponse
    {
        $day    = $request->query('day');
        $period = $request->query('period');

        $this->service->delete($id, $day, $period);

        return $this->successResponse(
            message: __('messages.deleted'),
            code:    204,
        );
    }
}
