<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\ClassController;
use App\Http\Controllers\SectionController;
use App\Http\Controllers\FeeTypeController;
use App\Http\Controllers\ClassWiseFeeController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\TeacherController;
use App\Http\Controllers\StudentWaiverController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\AccountController;
use App\Http\Controllers\TransactionController;
use App\Http\Controllers\ReportController;
use App\Http\Controllers\SettingsController;

Route::get('/', [AuthController::class, 'showLogin'])->name('login');
Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
Route::post('/login', [AuthController::class, 'login'])->name('login.post');

Route::get('/dashboard', [\App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard')->middleware('auth');

Route::middleware(['auth'])->group(function () {
    Route::get('/classes', [ClassController::class, 'index'])->name('classes.index');
    Route::post('/classes/store', [ClassController::class, 'store'])->name('classes.store');
	Route::post('/classes/update/{id}', [ClassController::class, 'update'])->name('classes.update');
    Route::post('/classes/delete/{id}', [ClassController::class, 'destroy'])->name('classes.delete');
	
	Route::get('/sections', [SectionController::class, 'index'])->name('sections.index');
	Route::post('/sections/store', [SectionController::class, 'store'])->name('sections.store');
	Route::post('/sections/update/{id}', [SectionController::class, 'update']);
	Route::post('/sections/delete/{id}', [SectionController::class, 'destroy']);
	
	Route::get('/fee-types', [FeeTypeController::class, 'index'])->name('feetypes.index');
    Route::post('/fee-types/store', [FeeTypeController::class, 'store'])->name('feetypes.store');
    Route::post('/fee-types/update/{id}', [FeeTypeController::class, 'update']);
    Route::post('/fee-types/delete/{id}', [FeeTypeController::class, 'destroy']);

	Route::get('/class-fees', [ClassWiseFeeController::class, 'index'])->name('classfees.index');
	Route::post('/class-fees/store', [ClassWiseFeeController::class, 'store'])->name('classfees.store');
	Route::post('/class-fees/delete/{id}', [ClassWiseFeeController::class, 'destroy']);
	
	Route::get('/students', [StudentController::class, 'index'])->name('students.index');
	Route::post('/students/store', [StudentController::class, 'store'])->name('students.store');
	Route::get('/students/edit/{id}', [StudentController::class, 'edit'])->name('students.edit');
	Route::post('/students/update', [StudentController::class, 'update'])->name('students.update');
	Route::post('/students/delete/{id}', [StudentController::class, 'destroy'])->name('students.delete');
	
	Route::get('/teachers', [TeacherController::class, 'index'])->name('teachers.index');
	Route::post('/teachers/store', [TeacherController::class, 'store'])->name('teachers.store');
	Route::get('/teachers/edit/{id}', [TeacherController::class, 'edit']);
	Route::post('/teachers/update', [TeacherController::class, 'update']);
	Route::post('/teachers/delete/{id}', [TeacherController::class, 'destroy']);
	
	Route::get('/waivers', [StudentWaiverController::class, 'index'])->name('waivers.index');
	Route::post('/waivers/store', [StudentWaiverController::class, 'store'])->name('waivers.store');
	Route::get('/waivers/edit/{id}', [StudentWaiverController::class, 'edit']);
	Route::post('/waivers/update', [StudentWaiverController::class, 'update']);
	Route::post('/waivers/delete/{id}', [StudentWaiverController::class, 'destroy']);
	
	Route::get('invoices', [InvoiceController::class, 'index'])->name('invoices.index');
	Route::post('invoices/generate', [InvoiceController::class, 'generate'])->name('fee.generate.process');
	Route::get('admin/invoices/details/{id}', [InvoiceController::class, 'getDetails']);
	Route::get('invoices/delete/{id}', [InvoiceController::class, 'deleteInvoice']);
	
	Route::get('admin/payments/collect', [PaymentController::class, 'index'])->name('payments.collect');
	Route::post('admin/payments/search', [PaymentController::class, 'searchStudent']);
	Route::post('admin/payments/store', [PaymentController::class, 'store']);
	Route::get('admin/payments/print/{id}', [PaymentController::class, 'printReceipt'])->name('payments.print');
	Route::get('admin/invoices/print/{id}', [InvoiceController::class, 'printInvoice']);
	Route::post('admin/payments/advance/store', [PaymentController::class, 'storeAdvance']);
	
	Route::get('/chart', [AccountController::class, 'index'])->name('accounts.chart');
    Route::post('/chart', [AccountController::class, 'store'])->name('accounts.store');
	
	Route::get('admin/transactions', [TransactionController::class, 'index'])->name('admin.transactions');
	Route::post('admin/transactions', [TransactionController::class, 'store']);
	Route::get('admin/transactions/{id}', [TransactionController::class, 'show']);
	Route::post('admin/transactions/update/{id}', [TransactionController::class, 'update']);
	Route::get('admin/reports/due', [ReportController::class, 'dueReport'])->name('reports.due');
	Route::get('admin/reports/income-expense', [ReportController::class, 'incomeExpenseReport'])->name('reports.income_expense');
	Route::get('admin/reports/due/print', [ReportController::class, 'dueReportPrint'])->name('reports.due.print');
	
	Route::get('admin/students/admission-form/{id}', [StudentController::class, 'printAdmissionForm'])->name('admin.students.print');
	Route::get('admin/students/id-cards/{class_id}', [StudentController::class, 'generateBulkIdCards'])->name('admin.students.id_cards');
});

Route::prefix('admin/accounts')->group(function () {
		Route::get('/chart', [AccountController::class, 'index'])->name('accounts.chart');
		Route::post('/chart', [AccountController::class, 'store'])->name('accounts.store');
		Route::get('/chart/{id}', [AccountController::class, 'show'])->name('accounts.show');
		Route::post('/chart/update/{id}', [AccountController::class, 'update'])->name('accounts.update');
		Route::delete('/chart/delete/{id}', [AccountController::class, 'destroy'])->name('accounts.destroy');
	});
	
	Route::prefix('admin/reports')->group(function () {
    Route::get('/collection', [ReportController::class, 'collectionReport'])->name('reports.collection');
    Route::get('/income-expense', [ReportController::class, 'incomeExpenseReport'])->name('reports.income_expense');
});

Route::prefix('admin/settings')->name('admin.settings.')->group(function () {
    Route::get('/company', [SettingsController::class, 'companySettings'])->name('company');
    Route::post('/company/update', [SettingsController::class, 'updateCompanySettings'])->name('company.update');
});