<?php

use App\Modules\CustomerPortal\Controllers\CustomerPortalAuthController;
use App\Modules\CustomerPortal\Controllers\CustomerPortalInvoiceController;
use App\Modules\CustomerPortal\Controllers\TenantPortalAccountController;
use Illuminate\Support\Facades\Route;

Route::prefix('customer-portal')->group(function (): void {
    Route::post('/auth/login', [CustomerPortalAuthController::class, 'login']);

    Route::middleware('auth:sanctum')->group(function (): void {
        Route::get('/me', [CustomerPortalAuthController::class, 'me']);
        Route::put('/profile', [CustomerPortalAuthController::class, 'updateProfile']);
        Route::post('/auth/logout', [CustomerPortalAuthController::class, 'logout']);
        Route::get('/dashboard', [CustomerPortalInvoiceController::class, 'dashboard']);
        Route::get('/invoices', [CustomerPortalInvoiceController::class, 'index']);
        Route::get('/invoices/{invoice}/export/html', [CustomerPortalInvoiceController::class, 'exportHtml']);
        Route::get('/invoices/{invoice}', [CustomerPortalInvoiceController::class, 'show']);
    });
});

Route::middleware(['auth:sanctum', 'tenant', 'feature:invoice', 'company.permission:invoice.manage'])
    ->group(function (): void {
        Route::get('/customers/{customer}/portal-account', [TenantPortalAccountController::class, 'show']);
        Route::put('/customers/{customer}/portal-account', [TenantPortalAccountController::class, 'save']);
        Route::post('/customers/{customer}/portal-account', [TenantPortalAccountController::class, 'store']);
        Route::post('/customers/{customer}/portal-account/revoke-tokens', [TenantPortalAccountController::class, 'revokeTokens']);
        Route::patch('/customers/{customer}/portal-account', [TenantPortalAccountController::class, 'update']);
    });
