import { Routes } from '@angular/router';

import { Home } from './pages/home/home';
import { Register } from './pages/register/register';
import { LoginComponent } from './pages/login/login';
import { Geral } from './pages/geral/geral';
import { Mureg } from './pages/mureg/mureg';
import { Faturamento } from './pages/faturamento/faturamento';

import { authGuard } from './guards/auth.guard';
import { sysadminOrGestorGuard } from './guards/sysadmin-or-gestor.guard';
import { sysadminOnlyGuard } from './guards/sysadmin-only.guard';
import { DadosUsuarios } from './pages/dados-usuarios/dados-usuarios';
import { VigenciaComponent } from './pages/vigencia/vigencia';
import { TrocaNumero } from './pages/troca-numero/troca-numero';
import { Dashboard } from './pages/dashboard/dashboard';
import { Notificacoes } from './pages/notificacoes/notificacoes';
import { ChipsControleRecebidos } from './pages/chips-controle-recebidos/chips-controle-recebidos';
import { Resumo } from './pages/resumo/resumo';
import { Parcelamentos } from './pages/parcelamentos/parcelamentos';
import { Historico } from './pages/historico/historico';
import { Perfil } from './pages/perfil/perfil';
import { SystemProvisionUserPage } from './pages/system-provision-user/system-provision-user';

export const routes: Routes = [
  { path: '', component: Home },
  { path: 'register', component: Register, title: 'Cadastro' },
  { path: 'login', component: LoginComponent, title: 'Login' },

  { path: 'geral', component: Geral, canActivate: [authGuard], title: 'Geral' },
  { path: 'mureg', component: Mureg, canActivate: [authGuard], title: 'Mureg' },
  { path: 'faturamento', component: Faturamento, canActivate: [authGuard, sysadminOrGestorGuard], title: 'Faturamento' },
  { path: 'dadosusuarios', component: DadosUsuarios, canActivate: [authGuard], title: 'Dados dos Usuários' },
  { path: 'vigencia', component: VigenciaComponent, canActivate: [authGuard], title: 'Vigência' },
  { path: 'trocanumero', component: TrocaNumero, canActivate: [authGuard], title: 'Troca de Número' },
  { path: 'notificacoes', component: Notificacoes, canActivate: [authGuard], title: 'Notificações' },
  { path: 'chips-controle-recebidos', component: ChipsControleRecebidos, canActivate: [authGuard, sysadminOrGestorGuard], title: 'Chips Controle Recebidos' },
  { path: 'resumo', component: Resumo, canActivate: [authGuard], title: 'Resumo' },
  { path: 'parcelamentos', component: Parcelamentos, canActivate: [authGuard, sysadminOrGestorGuard], title: 'Parcelamentos' },
  { path: 'historico', component: Historico, canActivate: [authGuard, sysadminOrGestorGuard], title: 'Histórico' },
  { path: 'perfil', component: Perfil, canActivate: [authGuard], title: 'Perfil' },
  {
    path: 'system/fornecer-usuario',
    component: SystemProvisionUserPage,
    canActivate: [authGuard, sysadminOnlyGuard],
    title: 'Criar Credenciais do Cliente',
  },

  // ✅ rota correta
  { path: 'dashboard', component: Dashboard, canActivate: [authGuard], title: 'Dashboard' },

  // ✅ compatibilidade: se alguém acessar /portal/dashboard, manda pra /dashboard
  { path: 'portal/dashboard', redirectTo: 'dashboard', pathMatch: 'full' },

  { path: '**', redirectTo: '' },
];
