<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Qms\QmsLotAuditConfirmRequest;
use App\Http\Requests\Qms\QmsLotAuditDocumentDetailRequest;
use App\Http\Requests\Qms\QmsLotAuditIndexRequest;
use App\Services\QmsLotAuditService;

class QmsLotAuditController extends Controller
{
    public function __construct(private QmsLotAuditService $service) {}

    /**
     * 품질관리서 목록 (로트 추적 심사용)
     */
    public function index(QmsLotAuditIndexRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->index($request->validated());
        }, __('message.fetched'));
    }

    /**
     * 품질관리서 상세 — 수주/개소 목록
     */
    public function show(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            return $this->service->show($id);
        }, __('message.fetched'));
    }

    /**
     * 수주 루트별 8종 서류 목록
     */
    public function routeDocuments(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            return $this->service->routeDocuments($id);
        }, __('message.fetched'));
    }

    /**
     * 서류 상세 조회 (2단계 로딩)
     */
    public function documentDetail(QmsLotAuditDocumentDetailRequest $request, string $type, int $id)
    {
        return ApiResponse::handle(function () use ($type, $id) {
            return $this->service->documentDetail($type, $id);
        }, __('message.fetched'));
    }

    /**
     * 개소별 로트 심사 확인 토글
     */
    public function confirm(QmsLotAuditConfirmRequest $request, int $id)
    {
        return ApiResponse::handle(function () use ($request, $id) {
            return $this->service->confirm($id, $request->validated());
        }, __('message.updated'));
    }
}
