<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\SubscriberController;
use App\Http\Controllers\LeadController;
use App\Http\Controllers\TicketController;
use App\Http\Controllers\PlanController;
use App\Http\Controllers\RouterController;
use App\Http\Controllers\LiveSessionController;
use App\Http\Controllers\VoucherController;
use App\Http\Controllers\FiberController;
use App\Http\Controllers\CommunicationController;
use App\Http\Controllers\ExpenseController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\ReportController;
use App\Http\Controllers\SettingController;

Route::get('/', function () {
    return redirect()->route('login');
});

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

// Protected ISP CRM Admin Panel Routes
Route::middleware(['auth'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/overview', [DashboardController::class, 'index'])->name('overview');

    // CUSTOMERS MODULE
    Route::get('/subscribers', [SubscriberController::class, 'index'])->name('subscribers.index');
    Route::post('/subscribers', [SubscriberController::class, 'store'])->name('subscribers.store');
    Route::delete('/subscribers/{subscriber}', [SubscriberController::class, 'destroy'])->name('subscribers.destroy');

    Route::get('/leads', [LeadController::class, 'index'])->name('leads.index');
    Route::post('/leads', [LeadController::class, 'store'])->name('leads.store');
    Route::patch('/leads/{lead}/status', [LeadController::class, 'updateStatus'])->name('leads.updateStatus');

    Route::get('/tickets', [TicketController::class, 'index'])->name('tickets.index');
    Route::post('/tickets', [TicketController::class, 'store'])->name('tickets.store');
    Route::patch('/tickets/{ticket}/status', [TicketController::class, 'updateStatus'])->name('tickets.updateStatus');

    // NETWORK MODULE
    Route::get('/network/sessions', [LiveSessionController::class, 'index'])->name('network.sessions');
    Route::delete('/network/sessions/{session}', [LiveSessionController::class, 'disconnect'])->name('network.disconnect');

    Route::get('/plans', [PlanController::class, 'index'])->name('plans.index');
    Route::post('/plans', [PlanController::class, 'store'])->name('plans.store');
    Route::patch('/plans/{plan}/status', [PlanController::class, 'updateStatus'])->name('plans.updateStatus');

    Route::get('/network/routers', [RouterController::class, 'index'])->name('network.routers');
    Route::post('/network/routers', [RouterController::class, 'store'])->name('network.storeRouter');
    Route::post('/network/routers/{router}/reboot', [RouterController::class, 'reboot'])->name('network.rebootRouter');

    Route::get('/network/fiber', [FiberController::class, 'index'])->name('network.fiber');
    Route::post('/network/fiber', [FiberController::class, 'store'])->name('network.storeFiber');

    // FINANCE MODULE
    Route::get('/finance/invoices', [InvoiceController::class, 'index'])->name('finance.invoices');
    Route::get('/finance/payments', [PaymentController::class, 'index'])->name('finance.payments');
    Route::get('/finance/expenses', [ExpenseController::class, 'index'])->name('finance.expenses');
    Route::post('/finance/expenses', [ExpenseController::class, 'store'])->name('finance.storeExpense');

    Route::get('/finance/vouchers', [VoucherController::class, 'index'])->name('finance.vouchers');
    Route::post('/finance/vouchers/batch', [VoucherController::class, 'generateBatch'])->name('finance.generateVouchers');
    Route::post('/finance/vouchers/agents', [VoucherController::class, 'storeAgent'])->name('finance.storeAgent');

    // OUTREACH MODULE
    Route::get('/communications/sms', [CommunicationController::class, 'index'])->name('communications.sms');
    Route::post('/communications/sms', [CommunicationController::class, 'sendSms'])->name('communications.sendSms');

    // INSIGHTS & ANALYTICS
    Route::get('/insights/analytics', [ReportController::class, 'index'])->name('insights.analytics');

    // SETTINGS
    Route::get('/settings', [SettingController::class, 'index'])->name('settings.index');
    Route::post('/settings', [SettingController::class, 'update'])->name('settings.update');
});
