<?php

use App\Http\Controllers\ExpenseCategoryController;
use App\Http\Controllers\ExpenseController;
use App\Http\Controllers\RecurringExpenseController;
use Illuminate\Support\Facades\Route;

Route::middleware('auth')->group(function (): void {
    Route::get('/expenses',[ExpenseController::class,'index'])->middleware('permission:expenses.view')->name('expenses.index');
    Route::get('/expenses/create',[ExpenseController::class,'create'])->middleware('permission:expenses.create')->name('expenses.create');
    Route::post('/expenses',[ExpenseController::class,'store'])->middleware('permission:expenses.create')->name('expenses.store');
    Route::get('/expenses/{expense}',[ExpenseController::class,'show'])->middleware(['permission:expenses.view','can:view,expense'])->name('expenses.show');
    Route::post('/expenses/{expense}/decision',[ExpenseController::class,'decision'])->middleware(['permission:expenses.approve','can:decide,expense'])->name('expenses.decision');
    Route::get('/expenses/{expense}/receipt',[ExpenseController::class,'receipt'])->middleware(['permission:expenses.view','can:view,expense'])->name('expenses.receipt');

    Route::get('/expense-categories',[ExpenseCategoryController::class,'index'])->middleware('permission:expenses.categories.manage')->name('expense-categories.index');
    Route::post('/expense-categories',[ExpenseCategoryController::class,'store'])->middleware('permission:expenses.categories.manage')->name('expense-categories.store');
    Route::put('/expense-categories/{category}',[ExpenseCategoryController::class,'update'])->middleware('permission:expenses.categories.manage')->name('expense-categories.update');

    Route::get('/recurring-expenses',[RecurringExpenseController::class,'index'])->middleware('permission:expenses.view')->name('recurring-expenses.index');
    Route::get('/recurring-expenses/create',[RecurringExpenseController::class,'create'])->middleware('permission:expenses.recurring.manage')->name('recurring-expenses.create');
    Route::post('/recurring-expenses',[RecurringExpenseController::class,'store'])->middleware('permission:expenses.recurring.manage')->name('recurring-expenses.store');
    Route::get('/recurring-expenses/{recurringExpense}/edit',[RecurringExpenseController::class,'edit'])->middleware(['permission:expenses.recurring.manage','can:manage,recurringExpense'])->name('recurring-expenses.edit');
    Route::put('/recurring-expenses/{recurringExpense}',[RecurringExpenseController::class,'update'])->middleware(['permission:expenses.recurring.manage','can:manage,recurringExpense'])->name('recurring-expenses.update');
    Route::post('/expense-reminders/{reminder}/acknowledge',[RecurringExpenseController::class,'acknowledge'])->middleware('permission:expenses.recurring.manage')->name('expense-reminders.acknowledge');
});