<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProviderClientBlockRequest;
use App\Http\Resources\ProviderClientBlockResource;
use App\Services\ProviderClientBlockService;
use Illuminate\Http\JsonResponse;

class ProviderClientBlockController extends Controller
{
    public function __construct(
        private ProviderClientBlockService $service
    ) {}

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

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

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

        return $this->successResponse(
            payload: new ProviderClientBlockResource($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 getBlockedClients(int $providerId): JsonResponse
    {
        $clientIds = $this->service->getBlockedClientIds($providerId);

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