<?php

/**
 * 문서 관리 API 라우트 (v1)
 *
 * - 문서 양식(템플릿) 조회
 * - 문서 CRUD
 * - 결재 워크플로우
 */

use App\Http\Controllers\Api\V1\Documents\DocumentController;
use App\Http\Controllers\Api\V1\Documents\DocumentTemplateController;
use Illuminate\Support\Facades\Route;

// 문서 양식(템플릿) - 읽기 전용
Route::prefix('document-templates')->group(function () {
    Route::get('/', [DocumentTemplateController::class, 'index'])->name('v1.document-templates.index');
    Route::get('/{id}', [DocumentTemplateController::class, 'show'])->whereNumber('id')->name('v1.document-templates.show');
});

// 문서 CRUD + 결재
Route::prefix('documents')->group(function () {
    // FQC 일괄생성 (제품검사)
    Route::post('/bulk-create-fqc', [DocumentController::class, 'bulkCreateFqc'])->name('v1.documents.bulk-create-fqc');
    Route::get('/fqc-status', [DocumentController::class, 'fqcStatus'])->name('v1.documents.fqc-status');

    // Resolve/Upsert (React 연동용)
    Route::get('/resolve', [DocumentController::class, 'resolve'])->name('v1.documents.resolve');
    Route::post('/upsert', [DocumentController::class, 'upsert'])->name('v1.documents.upsert');

    // 문서 CRUD
    Route::get('/', [DocumentController::class, 'index'])->name('v1.documents.index');
    Route::get('/{id}', [DocumentController::class, 'show'])->whereNumber('id')->name('v1.documents.show');
    Route::post('/', [DocumentController::class, 'store'])->name('v1.documents.store');
    Route::patch('/{id}', [DocumentController::class, 'update'])->whereNumber('id')->name('v1.documents.update');
    Route::delete('/{id}', [DocumentController::class, 'destroy'])->whereNumber('id')->name('v1.documents.destroy');

    // 결재 워크플로우
    Route::post('/{id}/submit', [DocumentController::class, 'submit'])->whereNumber('id')->name('v1.documents.submit');
    Route::post('/{id}/approve', [DocumentController::class, 'approve'])->whereNumber('id')->name('v1.documents.approve');
    Route::post('/{id}/reject', [DocumentController::class, 'reject'])->whereNumber('id')->name('v1.documents.reject');
    Route::post('/{id}/cancel', [DocumentController::class, 'cancel'])->whereNumber('id')->name('v1.documents.cancel');
});
