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 { GroupsPage } from 'src/app/modules/admin/groups/groups.page';
import { GroupFormPageComponent } from 'src/app/modules/admin/groups/form-page/group-form-page.component';
import { GroupsDataService } from 'src/app/modules/admin/groups/groups.data.service';
import { GroupsColumns } from 'src/app/modules/admin/groups/groups.columns';
import { HistoryComponent } from 'src/app/modules/admin/groups/history/history.component';

const routes: Routes = [
  {
    path: '',
    title: 'Groups',
    component: GroupsPage,
    children: [
      {
        path: 'create',
        component: GroupFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.groupsCreate],
          isInUserSpace: true,
        },
      },
      {
        path: 'edit/:id',
        component: GroupFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.groupsUpdate],
          isInUserSpace: true,
        },
      },
      {
        path: 'history/:historyId',
        component: HistoryComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.groups],
          isInUserSpace: true,
        },
      },
    ],
  },
];

@NgModule({
  declarations: [GroupsPage, GroupFormPageComponent, HistoryComponent],
  imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
  providers: [GroupsDataService.provide(), GroupsColumns.provide()],
})
export class GroupsModule {}
