<?php

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

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Construction\StructureReviewStoreRequest;
use App\Http\Requests\Construction\StructureReviewUpdateRequest;
use App\Services\Construction\StructureReviewService;
use Illuminate\Http\Request;

class StructureReviewController extends Controller
{
    public function __construct(private StructureReviewService $service) {}

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

    /**
     * 구조검토 상세 조회
     */
    public function show(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            return $this->service->show($id);
        }, __('message.structure_review.fetched'));
    }

    /**
     * 구조검토 등록
     */
    public function store(StructureReviewStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->store($request->validated());
        }, __('message.structure_review.created'));
    }

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

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

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

    /**
     * 구조검토 일괄 삭제
     */
    public function bulkDestroy(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            $this->service->bulkDestroy($request->input('ids', []));

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

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