<?php

use App\Http\Controllers\AuditCompanyController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\CompanyController;
use App\Http\Controllers\DirectorController;
use App\Http\Controllers\DirectorAppointmentController;
use App\Http\Controllers\CompanyRegisterExportController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

// Root redirect
Route::get('/', fn() => redirect()->route('dashboard'));

// Auth routes (Breeze)
require __DIR__.'/auth.php';

// Protected routes
Route::middleware(['auth'])->group(function () {
    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    
    // Super Admin routes - Audit Company Management
    Route::middleware(['role:super_admin'])->group(function () {
        Route::resource('audit-companies', AuditCompanyController::class);
        Route::get('/audit-companies/{auditCompany}/create-admin', [AuditCompanyController::class, 'createAdmin'])
            ->name('audit-companies.create-admin');
        Route::post('/audit-companies/{auditCompany}/store-admin', [AuditCompanyController::class, 'storeAdmin'])
            ->name('audit-companies.store-admin');
    });
    
    // Companies CRUD
    Route::resource('companies', CompanyController::class);
    
    // Directors CRUD
    Route::resource('directors', DirectorController::class);
    
    // Nested appointments routes
    Route::resource('companies.appointments', DirectorAppointmentController::class)
        ->except(['show']);
    
    // Export routes
    Route::get('/companies/{company}/export-directors-docx', [CompanyRegisterExportController::class, 'exportDirectorsDocx'])
        ->name('companies.export-directors-docx');
    
    // Profile routes (Breeze)
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});