import { NgModule } from '@angular/core';
import { RouterModule, Routes, CanLoad } from '@angular/router';
import { ErrorPageComponent } from './shared/error-page/error-page.component';
import { AgenteReservaGuard } from './auth/guards/agente-reserva.guard';
import { SupervisorGuard } from './auth/guards/supervisor.guard';
import { PasajeroGuard } from './auth/guards/pasajero.guard';

const routes: Routes = [
  {
    path: 'auth',
    loadChildren: () => import('./auth/auth.module').then(m => m.AuthModule)
  },
  {
    path: 'pasajeros',
    loadChildren: () => import('./pasajeros/pasajeros.module').then(m => m.PasajerosModule),
    canLoad: [AgenteReservaGuard],
    canActivate: [AgenteReservaGuard]
  },
  {
    path: 'aeropuertos',
    loadChildren: () => import('./aeropuertos/aeropuertos.module').then(m => m.AeropuertosModule),
    canLoad: [SupervisorGuard],
    canActivate: [SupervisorGuard]
  },
  {
    path: 'agentes',
    loadChildren: () => import('./agentes/agentes.module').then(m => m.AgentesModule),
    canLoad: [SupervisorGuard],
    canActivate: [SupervisorGuard]
  },
  {
    path: 'vuelos',
    loadChildren: () => import('./vuelos/vuelos.module').then(m => m.VuelosModule),
    canLoad: [SupervisorGuard],
    canActivate: [SupervisorGuard]
  },
  {
    path: 'pagos',
    loadChildren: () => import('./pagos/pagos.module').then(m => m.PagosModule),
    canLoad: [AgenteReservaGuard],
    canActivate: [AgenteReservaGuard]
  },
  {
    path: 'pago-reserva',
    loadChildren: () => import('./pago-reserva/pago-reserva.module').then(m => m.PagoReservaModule),
    canLoad: [PasajeroGuard],
    canActivate: [PasajeroGuard]
  },
  {
    path: 'reservas',
    loadChildren: () => import('./reservas/reservas.module').then(m => m.ReservasModule),
    canLoad: [AgenteReservaGuard],
    canActivate: [AgenteReservaGuard]
  },
  {
    path: '404',
    component: ErrorPageComponent
  },
  {
    path: '**', 
    redirectTo: '/auth/login'
  }
]

@NgModule({
  imports: [
    RouterModule.forRoot(routes)
  ],
  exports: [
    RouterModule
  ]
})
export class AppRouterModule { }
