<?php

use Illuminate\Support\Facades\Route;
use App\Modules\FINANCE\Http\Controllers\DashboardController;
use App\Modules\FINANCE\Http\Controllers\InvoiceController;
use App\Modules\FINANCE\Http\Controllers\RecurringInvoiceController;
use App\Modules\FINANCE\Http\Controllers\SubscriptionController;
use App\Modules\FINANCE\Http\Controllers\PaymentController;
use App\Modules\FINANCE\Http\Controllers\CreditNoteController;
use App\Modules\FINANCE\Http\Controllers\TaxController;
use App\Modules\FINANCE\Http\Controllers\PublicInvoiceController;

Route::middleware(['web', 'auth', 'branch'])->prefix('finance')->name('finance.')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    
    // Invoices
    Route::resource('invoices', InvoiceController::class)->names([
        'index' => 'invoices.index'
    ]);
    Route::post('invoices/{invoice}/status',    [InvoiceController::class, 'status'])->name('invoices.status');
    Route::post('invoices/{invoice}/duplicate', [InvoiceController::class, 'duplicate'])->name('invoices.duplicate');
    Route::post('invoices/{invoice}/send',      [InvoiceController::class, 'send'])->name('invoices.send');
    Route::get('invoices/{invoice}/download',   [InvoiceController::class, 'download'])->name('invoices.download');
    
    // Recurring Invoices
    Route::resource('recurring', RecurringInvoiceController::class)->names('recurring');
    
    // Subscriptions
    Route::resource('subscriptions', SubscriptionController::class)->names('subscriptions');
    
    // Payments
    Route::resource('payments', PaymentController::class)->names('payments');
    
    // Credit Notes
    Route::resource('credit-notes', CreditNoteController::class)->names('credit-notes');
    
    // Taxes
    Route::resource('taxes', TaxController::class)->names('taxes');
    
});

// Public Invoice Routes (No Auth)
Route::middleware(['web'])->name('public.')->group(function () {
    Route::get('/public/invoice/{hash}', [PublicInvoiceController::class, 'show'])->name('invoice.show');
    Route::get('/public/invoice/{hash}/download', [PublicInvoiceController::class, 'download'])->name('invoice.download');
});
