<?php

use App\Http\Controllers\Admin\NavigationStateController;
use App\Http\Controllers\Api\AiStatusController;
use App\Http\Controllers\Api\ImageController;
use App\Http\Controllers\Api\SparkboothUploadController;
use App\Http\Controllers\Api\StyleController;
use App\Http\Controllers\DownloadController;
use App\Http\Controllers\PrintController;
use Illuminate\Http\Request;
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 and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

Route::get('/ai-status', [AiStatusController::class, 'checkStatus']);
Route::post('/ai-status/update', [AiStatusController::class, 'checkAndUpdateStatus']);
Route::post('/sparkbooth/upload', [SparkboothUploadController::class, 'store'])
    ->middleware('throttle:30,1')
    ->name('api.sparkbooth.upload');

Route::post('/admin/navigation-state', [NavigationStateController::class, 'store'])->middleware('auth:sanctum');

Route::middleware('gallery.access')->group(function () {
    Route::get('/images', [ImageController::class, 'index']);
    Route::get('/styles', [StyleController::class, 'index']);
    Route::get('/image-refresh-interval', [StyleController::class, 'getImageRefreshInterval']);
    Route::get('/max-copies-setting', [StyleController::class, 'getMaxNumberOfCopies']);

    Route::post('/images/style-change', [ImageController::class, 'styleChangeRequest']);
    Route::get('/comfyui-url', [ImageController::class, 'getComfyUiUrl']);
    Route::delete('/images/{image}/styled', [ImageController::class, 'deleteStyled']);

    Route::middleware('auth:sanctum')->group(function () {
        Route::post('/images/keep', [ImageController::class, 'keepImage']);
        Route::delete('/images/{image}', [ImageController::class, 'deleteImage']);
        Route::get('/images/status', [ImageController::class, 'getStatus']);
    });

    Route::get('/images/fetch-styled/{prompt_id}', [ImageController::class, 'fetchStyledImage']);
    Route::post('/print-image', [PrintController::class, 'printImage']);
    Route::post('/download-image', [DownloadController::class, 'downloadImage']);
});
