<?php

namespace App\Http\Controllers;

use App\Http\Requests\ClientProviderBlockRequest;
use App\Http\Resources\ClientProviderBlockResource;
use App\Services\ClientProviderBlockService;
use Illuminate\Http\JsonResponse;

class ClientProviderBlockController extends Controller
{
    public function __construct(
        private ClientProviderBlockService $service
    ) {}

    public function index(int $clientId): JsonResponse
    {
        $blocks = $this->service->getByClientId($clientId);

        return $this->successResponse(
            payload: ClientProviderBlockResource::collection($blocks),
        );
    }

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

        return $this->successResponse(
            payload: new ClientProviderBlockResource($block),
            message: __('messages.created'),
            code:    201,
        );
    }

    public function destroy(int $id): JsonResponse
    {
        $this->service->delete($id);

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

    //

    public function getBlockedProviders(int $clientId): JsonResponse
    {
        $providerIds = $this->service->getBlockedProviderIds($clientId);

        return $this->successResponse(
            payload: $providerIds,
        );
    }
}
