<?php

use App\Modules\Invoice\Controllers\CustomerController;
use App\Modules\Invoice\Controllers\InvoiceController;
use App\Modules\Invoice\Controllers\PaymentController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth:sanctum', 'tenant', 'feature:invoice'])->group(function (): void {
    Route::middleware('company.permission:invoice.view')->group(function (): void {
        Route::get('/customers', [CustomerController::class, 'index']);
        Route::get('/invoices', [InvoiceController::class, 'index']);
        Route::get('/invoices/{invoice}/export/html', [InvoiceController::class, 'exportHtml']);
        Route::get('/invoices/{invoice}', [InvoiceController::class, 'show']);
    });

    Route::middleware('company.permission:invoice.manage')->group(function (): void {
        Route::post('/customers', [CustomerController::class, 'store']);
        Route::patch('/customers/{customer}', [CustomerController::class, 'update']);
        Route::post('/invoices', [InvoiceController::class, 'store']);
        Route::patch('/invoices/{invoice}', [InvoiceController::class, 'update']);
        Route::post('/invoices/{invoice}/payments', [PaymentController::class, 'store']);
    });
});
