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";

const routes: Routes = [
  {
    path: "",
    title: "Groups",
    component: GroupsPage,
    children: [
      {
        path: "create",
        component: GroupFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.apiKeysCreate],
        },
      },
      {
        path: "edit/:id",
        component: GroupFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.apiKeysUpdate],
        },
      },
    ],
  },
];

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