import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { authGuard } from '../core/guards/auth.guard';
import { roleGuard } from '../core/guards/role.guard';
import { Users } from '@modules/users/users';

// Composants principaux
import { DcbDashboard } from './dcb-dashboard/dcb-dashboard';

import { Team } from './team/team';
import { Transactions } from './transactions/transactions';
import { TransactionsList } from './transactions/list/list';
import { TransactionDetails } from './transactions/details/details';

import { Merchants } from './merchants/merchants';
import { MerchantsList } from './merchants/list/list';
import { MerchantsConfig } from './merchants/config/config';
import { MerchantsHistory } from './merchants/history/history';

import { Operators } from './operators/operators';
import { OperatorsConfig } from './operators/config/config';
import { OperatorsStats } from './operators/stats/stats';

import { Webhooks } from './webhooks/webhooks';
import { WebhooksHistory } from './webhooks/history/history';
import { WebhooksStatus } from './webhooks/status/status';
import { WebhooksRetry } from './webhooks/retry/retry';

import { Settings } from './settings/settings';
import { Integrations } from './integrations/integrations';
import { Support } from './support/support';
import { MyProfile } from './profile/profile';
import { Documentation } from './documentation/documentation';
import { Help } from './help/help';
import { About } from './about/about';


const routes: Routes = [


  // ---------------------------
  // Users
  // ---------------------------
  {
    path: 'users',
    canActivate: [authGuard, roleGuard],
    component: Users,
    data: { 
      title: 'Gestion des Utilisateurs',
      requiredRoles: ['admin'] // pour information
    }
  },

  // ---------------------------
  // Dashboard & Team
  // ---------------------------
  {
    path: 'dcb-dashboard',
    canActivate: [authGuard, roleGuard], 
    component: DcbDashboard,
    data: { 
      title: 'Dashboard DCB',
      requiredRoles: ['admin', 'merchant', 'support'] 
    }
  },

  {
    path: 'team',
    component: Team,
    canActivate: [authGuard, roleGuard],
    data: { title: 'Team' }
  },

  // ---------------------------
  // Transactions
  // ---------------------------
  {
    path: 'transactions',
    component: Transactions,
    canActivate: [authGuard, roleGuard],
    data: { 
      title: 'Transactions DCB',
      requiredRoles: ['admin', 'merchant', 'support'] 
    }
  },
  {
    path: 'transactions/:id',
    component: Transactions,
    canActivate: [authGuard, roleGuard],
    data: { 
      title: 'Détails Transaction',
      requiredRoles: ['admin', 'merchant', 'support'] 
    }
  },

  // ---------------------------
  // Merchants
  // ---------------------------
  {
    path: 'merchants',
    canActivate: [authGuard, roleGuard],
    children: [
      { path: 'list', component: MerchantsList, data: { title: 'Liste des Marchands' } },
      { path: 'config', component: MerchantsConfig, data: { title: 'Configuration API / Webhooks' } },
      { path: 'history', component: MerchantsHistory, data: { title: 'Statistiques & Historique' } },
    ]
  },

  // ---------------------------
  // Operators
  // ---------------------------
  {
    path: 'operators',
    canActivate: [authGuard, roleGuard],
    children: [
      { path: 'config', component: OperatorsConfig, data: { title: 'Paramètres d\'Intégration' } },
      { path: 'stats', component: OperatorsStats, data: { title: 'Performance & Monitoring' } },
    ]
  },

  // ---------------------------
  // Webhooks
  // ---------------------------
  {
    path: 'webhooks',
    canActivate: [authGuard, roleGuard],
    children: [
      { path: 'history', component: WebhooksHistory, data: { title: 'Historique' } },
      { path: 'status', component: WebhooksStatus, data: { title: 'Statut des Requêtes' } },
      { path: 'retry', component: WebhooksRetry, data: { title: 'Relancer Webhook' } },
    ]
  },

  // ---------------------------
  // Settings & Integrations (Admin seulement)
  // ---------------------------
  { 
    path: 'settings', 
    component: Settings, 
    canActivate: [authGuard, roleGuard], 
    data: { title: 'Paramètres Système' } 
  },
  { 
    path: 'integrations', 
    component: Integrations, 
    canActivate: [authGuard, roleGuard], 
    data: { title: 'Intégrations Externes' } 
  },

  // ---------------------------
  // Support & Profile (Tous les utilisateurs authentifiés)
  // ---------------------------
  { 
    path: 'support', 
    component: Support, 
    canActivate: [authGuard, roleGuard], 
    data: { title: 'Support' } 
  },
  {
    path: 'profile',
    component: MyProfile,
    canActivate: [authGuard, roleGuard],
    data: { title: 'Mon Profil' }
  },

  // ---------------------------
  // Documentation & Help (Tous les utilisateurs authentifiés)
  // ---------------------------
  { 
    path: 'documentation', 
    component: Documentation, 
    canActivate: [authGuard, roleGuard], 
    data: { title: 'Documentation' } 
  },
  { 
    path: 'help', 
    component: Help, 
    canActivate: [authGuard, roleGuard], 
    data: { title: 'Aide' } 
  },
  { 
    path: 'about', 
    component: About, 
    canActivate: [authGuard, roleGuard], 
    data: { title: 'À propos' } 
  },
];

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