<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Inspection\InspectionCompleteRequest;
use App\Http\Requests\Inspection\InspectionStoreRequest;
use App\Http\Requests\Inspection\InspectionUpdateRequest;
use App\Services\InspectionService;
use Illuminate\Http\Request;

class InspectionController extends Controller
{
    public function __construct(private InspectionService $service) {}

    /**
     * 목록 조회
     */
    public function index(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->index($request->all());
        }, __('message.inspection.fetched'));
    }

    /**
     * 통계 조회
     */
    public function stats(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->stats($request->all());
        }, __('message.inspection.fetched'));
    }

    /**
     * 캘린더 스케줄 조회
     */
    public function calendar(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->calendar($request->all());
        }, __('message.inspection.fetched'));
    }

    /**
     * 단건 조회
     */
    public function show(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            return $this->service->show($id);
        }, __('message.inspection.fetched'));
    }

    /**
     * 생성
     */
    public function store(InspectionStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->store($request->validated());
        }, __('message.inspection.created'));
    }

    /**
     * 수정
     */
    public function update(InspectionUpdateRequest $request, int $id)
    {
        return ApiResponse::handle(function () use ($request, $id) {
            return $this->service->update($id, $request->validated());
        }, __('message.inspection.updated'));
    }

    /**
     * 삭제
     */
    public function destroy(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $this->service->destroy($id);

            return 'success';
        }, __('message.inspection.deleted'));
    }

    /**
     * 검사 완료 처리
     */
    public function complete(InspectionCompleteRequest $request, int $id)
    {
        return ApiResponse::handle(function () use ($request, $id) {
            return $this->service->complete($id, $request->validated());
        }, __('message.inspection.completed'));
    }
}
