<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\V1\AiReport\AiReportGenerateRequest;
use App\Http\Requests\V1\AiReport\AiReportListRequest;
use App\Services\AiReportService;
use Illuminate\Http\JsonResponse;

class AiReportController extends Controller
{
    public function __construct(
        private readonly AiReportService $service
    ) {}

    /**
     * AI 리포트 목록 조회
     */
    public function index(AiReportListRequest $request): JsonResponse
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->list($request->validated());
        }, __('message.ai_report.fetched'));
    }

    /**
     * AI 리포트 생성
     */
    public function generate(AiReportGenerateRequest $request): JsonResponse
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->generate($request->validated());
        }, __('message.ai_report.generated'), 201);
    }

    /**
     * AI 리포트 상세 조회
     */
    public function show(int $id): JsonResponse
    {
        return ApiResponse::handle(function () use ($id) {
            return $this->service->show($id);
        }, __('message.ai_report.fetched'));
    }

    /**
     * AI 리포트 삭제
     */
    public function destroy(int $id): JsonResponse
    {
        return ApiResponse::handle(function () use ($id) {
            $this->service->delete($id);

            return null;
        }, __('message.ai_report.deleted'));
    }
}
