<?php

namespace App\Http\Controllers;

use App\Http\Requests\ReviewImprovementRequest;
use App\Http\Resources\ReviewImprovementResource;
use App\Services\ReviewImprovementService;
use Illuminate\Http\JsonResponse;

class ReviewImprovementController extends Controller
{
    public function __construct(
        private ReviewImprovementService $service
    ) {}

    public function index(int $reviewId): JsonResponse
    {
        $items = $this->service->getByReviewId($reviewId);

        return $this->successResponse(
            payload: ReviewImprovementResource::collection($items),
        );
    }

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

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

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

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