<?php

/**
 * 전자계약(E-Sign) API 라우트 (v1)
 *
 * - 계약 관리 (인증 필요)
 * - 서명 프로세스 (토큰 기반, 비인증)
 */

use App\Http\Controllers\Api\V1\ESign\EsignContractController;
use App\Http\Controllers\Api\V1\ESign\EsignSignController;
use Illuminate\Support\Facades\Route;

// E-Sign Contract API (인증 필요 - auth.apikey 그룹 내)
Route::prefix('esign/contracts')->group(function () {
    Route::get('', [EsignContractController::class, 'index'])->name('v1.esign.contracts.index');
    Route::post('', [EsignContractController::class, 'store'])->name('v1.esign.contracts.store');
    Route::get('/stats', [EsignContractController::class, 'stats'])->name('v1.esign.contracts.stats');
    Route::get('/{id}', [EsignContractController::class, 'show'])->whereNumber('id')->name('v1.esign.contracts.show');
    Route::post('/{id}/cancel', [EsignContractController::class, 'cancel'])->whereNumber('id')->name('v1.esign.contracts.cancel');
    Route::post('/{id}/fields', [EsignContractController::class, 'configureFields'])->whereNumber('id')->name('v1.esign.contracts.fields');
    Route::post('/{id}/send', [EsignContractController::class, 'send'])->whereNumber('id')->name('v1.esign.contracts.send');
    Route::post('/{id}/remind', [EsignContractController::class, 'remind'])->whereNumber('id')->name('v1.esign.contracts.remind');
    Route::get('/{id}/download', [EsignContractController::class, 'download'])->whereNumber('id')->name('v1.esign.contracts.download');
    Route::get('/{id}/verify', [EsignContractController::class, 'verify'])->whereNumber('id')->name('v1.esign.contracts.verify');
});

// E-Sign Sign API (토큰 기반, 비인증 - auth.apikey 그룹 내에서 토큰으로 접근)
Route::prefix('esign/sign/{token}')->group(function () {
    Route::get('', [EsignSignController::class, 'getContract'])->name('v1.esign.sign.contract');
    Route::post('/otp/send', [EsignSignController::class, 'sendOtp'])->name('v1.esign.sign.otp.send');
    Route::post('/otp/verify', [EsignSignController::class, 'verifyOtp'])->name('v1.esign.sign.otp.verify');
    Route::get('/document', [EsignSignController::class, 'getDocument'])->name('v1.esign.sign.document');
    Route::post('/submit', [EsignSignController::class, 'submit'])->name('v1.esign.sign.submit');
    Route::post('/reject', [EsignSignController::class, 'reject'])->name('v1.esign.sign.reject');
});
