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 { ShortUrlsPage } from 'src/app/modules/admin/short-urls/short-urls.page';
import { ShortUrlFormPageComponent } from 'src/app/modules/admin/short-urls/form-page/short-url-form-page.component';
import { ShortUrlsDataService } from 'src/app/modules/admin/short-urls/short-urls.data.service';
import { ShortUrlsColumns } from 'src/app/modules/admin/short-urls/short-urls.columns';
import { HistoryComponent } from 'src/app/modules/admin/short-urls/history/history.component';

const routes: Routes = [
  {
    path: '',
    title: 'ShortUrls',
    component: ShortUrlsPage,
    children: [
      {
        path: 'create',
        component: ShortUrlFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.shortUrlsCreate],
          isInUserSpace: true,
        },
      },
      {
        path: 'edit/:id',
        component: ShortUrlFormPageComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.shortUrlsUpdate],
          isInUserSpace: true,
        },
      },
      {
        path: 'history/:historyId',
        component: HistoryComponent,
        canActivate: [PermissionGuard],
        data: {
          permissions: [PermissionsEnum.shortUrls],
          isInUserSpace: true,
        },
      },
    ],
  },
];

@NgModule({
  declarations: [ShortUrlsPage, ShortUrlFormPageComponent, HistoryComponent],
  imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
  providers: [ShortUrlsDataService.provide(), ShortUrlsColumns.provide()],
})
export class ShortUrlsModule {}
