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 { UserFormPageComponent } from 'src/app/modules/admin/administration/users/form-page/user-form-page.component';
import { UsersPage } from 'src/app/modules/admin/administration/users/users.page';
import { UsersDataService } from 'src/app/modules/admin/administration/users/users.data.service';
import { UsersColumns } from 'src/app/modules/admin/administration/users/users.columns';
import { HistoryComponent } from 'src/app/modules/admin/administration/users/history/history.component';

const routes: Routes = [
  {
    path: '',
    title: 'Admin - Users | Maxlan',
    component: UsersPage,
    children: [
      {
        path: 'create',
        component: UserFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.usersCreate],
        },
      },
      {
        path: 'edit/:id',
        component: UserFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.usersUpdate],
        },
      },
      {
        path: 'history/:historyId',
        component: HistoryComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.users],
        },
      },
    ],
  },
];

@NgModule({
  declarations: [UsersPage, UserFormPageComponent, HistoryComponent],
  imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
  providers: [UsersDataService.provide(), UsersColumns.provide()],
})
export class UsersModule {}
