<?php

namespace App\Http\Controllers\Api\V1\Construction;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Construction\HandoverReportStoreRequest;
use App\Http\Requests\Construction\HandoverReportUpdateRequest;
use App\Services\Construction\HandoverReportService;
use Illuminate\Http\Request;

class HandoverReportController extends Controller
{
    public function __construct(private HandoverReportService $service) {}

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

    /**
     * 인수인계보고서 상세 조회
     */
    public function show(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            return $this->service->show($id);
        }, __('message.handover_report.fetched'));
    }

    /**
     * 인수인계보고서 등록
     */
    public function store(HandoverReportStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->store($request->validated());
        }, __('message.handover_report.created'));
    }

    /**
     * 인수인계보고서 수정
     */
    public function update(HandoverReportUpdateRequest $request, int $id)
    {
        return ApiResponse::handle(function () use ($request, $id) {
            return $this->service->update($id, $request->validated());
        }, __('message.handover_report.updated'));
    }

    /**
     * 인수인계보고서 삭제
     */
    public function destroy(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $this->service->destroy($id);

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

    /**
     * 인수인계보고서 일괄 삭제
     */
    public function bulkDestroy(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            $this->service->bulkDestroy($request->input('ids', []));

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

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