<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Route;
use Maestro\Core\Modules\Offers\Http\Controllers\OfferCatalogController;
use Maestro\Core\Modules\Offers\Http\Controllers\OfferController;
use Maestro\Core\Modules\Offers\Http\Controllers\OfferPublicController;
use Maestro\Core\Modules\Offers\Http\Controllers\OfferTemplateController;

Route::middleware(['web', 'throttle:120,1'])
    ->prefix('api/offers/public')
    ->group(function (): void {
        Route::get('/{uuid}', [OfferPublicController::class, 'show']);
        Route::post('/{uuid}/accept', [OfferPublicController::class, 'accept']);
        Route::post('/{uuid}/decline', [OfferPublicController::class, 'decline']);
    });

Route::middleware(['web', 'auth:sanctum', 'maestro.module:offers'])
    ->prefix('api/offers')
    ->group(function (): void {
        Route::get('/meta/editor-context', [OfferController::class, 'metaEditorContext']);
        Route::patch('/meta/vat-presets', [OfferController::class, 'patchVatPresets']);

        Route::get('/catalog/items', [OfferCatalogController::class, 'index']);
        Route::post('/catalog/items', [OfferCatalogController::class, 'store']);
        Route::get('/catalog/items/{catalog_item}', [OfferCatalogController::class, 'show']);
        Route::patch('/catalog/items/{catalog_item}', [OfferCatalogController::class, 'update']);
        Route::delete('/catalog/items/{catalog_item}', [OfferCatalogController::class, 'destroy']);

        Route::patch('/templates/{offer}', [OfferTemplateController::class, 'updateName']);

        Route::get('/', [OfferController::class, 'index']);
        Route::post('/', [OfferController::class, 'store']);
        Route::post('/from-template', [OfferController::class, 'duplicateFromTemplate']);
        Route::get('/{offer}', [OfferController::class, 'show']);
        Route::patch('/{offer}', [OfferController::class, 'update']);
        Route::delete('/{offer}', [OfferController::class, 'destroy']);
        Route::get('/{offer}/pdf', [OfferController::class, 'pdf']);
        Route::post('/{offer}/send', [OfferController::class, 'sendOffer']);
        Route::post('/{offer}/convert-to-project', [OfferController::class, 'convertToProject']);
    });
