<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\TwoFactorController;
use App\Http\Controllers\Api\DashboardController;
use App\Http\Controllers\Api\PatientController;
use App\Http\Controllers\Api\AppointmentController;
use App\Http\Controllers\Api\TherapistController;
use App\Http\Controllers\Api\InvoiceController;
use App\Http\Controllers\Api\PaymentController;
use App\Http\Controllers\Api\PackageController;
use App\Http\Controllers\Api\LedgerController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
*/

// Public API routes
Route::post('/register', [AuthController::class, 'register']);
Route::post('/login', [AuthController::class, 'login']);
Route::post('/verify-2fa', [AuthController::class, 'verify2FA']);

// Protected API routes
Route::middleware('auth:sanctum')->group(function () {
    // Auth
    Route::post('/logout', [AuthController::class, 'logout']);
    Route::get('/user', [AuthController::class, 'user']);
    
    // 2FA
    Route::get('/2fa/status', [TwoFactorController::class, 'status']);
    Route::get('/2fa/enable', [TwoFactorController::class, 'enable']);
    Route::post('/2fa/confirm', [TwoFactorController::class, 'confirm']);
    Route::post('/2fa/disable', [TwoFactorController::class, 'disable']);
    Route::get('/2fa/recovery-codes', [TwoFactorController::class, 'regenerateRecoveryCodes']);
    
    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index']);
    
    // Patients
    Route::apiResource('patients', PatientController::class);
    Route::get('/patients/{patient}/profile', [PatientController::class, 'profile']);
    
    // Appointments
    Route::apiResource('appointments', AppointmentController::class);
    Route::get('/appointments/calendar/feed', [AppointmentController::class, 'calendar']);
    Route::get('/appointments/available-slots', [AppointmentController::class, 'availableSlots']);
    
    // Therapists
    Route::apiResource('therapists', TherapistController::class);
    Route::get('/therapists/{user}/performance', [TherapistController::class, 'performance']);
    Route::get('/therapists/{user}/wage-calculate', [TherapistController::class, 'calculateWage']);
    Route::post('/therapists/{user}/wage', [TherapistController::class, 'storeWage']);
    
    // Invoices
    Route::apiResource('invoices', InvoiceController::class);
    Route::get('/invoices/summary/report', [InvoiceController::class, 'summary']);
    
    // Payments
    Route::apiResource('payments', PaymentController::class)->except(['update']);
    Route::get('/payments/summary/report', [PaymentController::class, 'summary']);
    
    // Packages
    Route::apiResource('packages', PackageController::class);
    Route::post('/packages/assign', [PackageController::class, 'assignToPatient']);
    Route::get('/patient-packages', [PackageController::class, 'patientPackages']);
    
    // Ledger
    Route::apiResource('ledger', LedgerController::class)->except(['show', 'update', 'destroy']);
    Route::get('/ledger/summary/pl', [LedgerController::class, 'summary']);
    Route::get('/ledger/summary/income', [LedgerController::class, 'incomeSummary']);
    Route::get('/ledger/summary/expenses', [LedgerController::class, 'expenseSummary']);
});
