import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from 'src/app/modules/shared/shared.module';
import { RouterModule, Routes } from '@angular/router';
import { PermissionGuard } from 'src/app/core/guard/permission.guard';
import { PermissionsEnum } from 'src/app/model/auth/permissionsEnum';
import { DomainsPage } from 'src/app/modules/admin/administration/domains/domains.page';
import { DomainFormPageComponent } from 'src/app/modules/admin/administration/domains/form-page/domain-form-page.component';
import { DomainsDataService } from 'src/app/modules/admin/administration/domains/domains.data.service';
import { DomainsColumns } from 'src/app/modules/admin/administration/domains/domains.columns';
import { HistoryComponent } from 'src/app/modules/admin/administration/domains/history/history.component';

const routes: Routes = [
  {
    path: '',
    title: 'Domains',
    component: DomainsPage,
    children: [
      {
        path: 'create',
        component: DomainFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.apiKeysCreate],
        },
      },
      {
        path: 'edit/:id',
        component: DomainFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.apiKeysUpdate],
        },
      },
      {
        path: 'history/:historyId',
        component: HistoryComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.domains],
        },
      },
    ],
  },
];

@NgModule({
  declarations: [DomainsPage, DomainFormPageComponent, HistoryComponent],
  imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
  providers: [DomainsDataService.provide(), DomainsColumns.provide()],
})
export class DomainsModule {}
