<?php

use App\Http\Controllers\AcceptanceLetterController;
use App\Http\Controllers\AcceptanceTemplateController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\CompletionLetterController;
use App\Http\Controllers\CompletionTemplateController;
use App\Http\Controllers\FileViewController;
use App\Http\Controllers\LetterController;
use App\Models\FileUpload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group.
|
*/

// Authentication Routes
Route::post('/login', [AuthController::class, 'login']);

// Protected Route
Route::middleware('auth:sanctum')->group(function () {
    // Letter Management Routes
    Route::apiResource('letter', LetterController::class);
    Route::get('/letters/search', [LetterController::class, 'search']);

    // File Attachment Routes
    Route::get('/lampiran/{id}', [LetterController::class, 'letterLampiran'])
        ->name('letters.lampiran');

    // Template Management Routes
    Route::apiResource('completion_templates', CompletionTemplateController::class);
    Route::apiResource('acceptance_templates', AcceptanceTemplateController::class);

    Route::get('/generate-surat/acc/{id}', [LetterController::class, 'generateSuratAcc']);
    Route::get('/generate-surat/comp/{id}', [LetterController::class, 'generateSuratComp']);

    // File Viewer Route (Internal use for signed URLs)
    Route::get('/file/{id}', [FileViewController::class, 'show'])
        ->name('file.view')
        ->middleware('signed');
});

/**
 * API Endpoints Documentation:
 *
 * GET    /api/user                    - Get authenticated user
 *
 * Letters:
 * GET    /api/letters                 - List all letters
 * POST   /api/letters                 - Create new letter
 * GET    /api/letters/{id}            - Get letter details
 * PUT    /api/letters/{id}            - Update letter
 * DELETE /api/letters/{id}            - Delete letter
 * GET    /api/letters/lampiran/{id}   - Get file attachment URL
 *
 * Templates:
 * GET    /api/completion_templates    - List completion templates
 * GET    /api/acceptance_templates    - List acceptance templates
 *
 * Letter Types:
 * GET    /api/acceptance_letters      - List acceptance letters
 * GET    /api/completion_letters      - List completion letters
 *
 * File Handling:
 * GET    /api/file/{id}              - View file (internal, signed URL)
 */
