import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { OrderingDirection } from '@shared/ui-api/interfaces/route-config/ordering-directions';
import { AuthGuard } from '@shared/auth/auth.guard';
import { FilterTypes } from '@shared/ui-api/interfaces/route-config/filter-types';
import { PeriodicTaskLogListComponent } from './periodic-task-log-list/periodic-task-log-list.component';
import { PeriodicTaskLogListResolver } from '@fleio-api/logger/periodic-task-log-list.resolver';
import { PeriodicTaskLogDetailsComponent } from './periodic-task-log-details/periodic-task-log-details.component';
import { PeriodicTaskLogResolver } from '@fleio-api/logger/periodic-task-log.resolver';

const routes: Routes = [
  {
    path: '',
    component: PeriodicTaskLogListComponent,
    resolve: {
      periodicTaskLogEntries: PeriodicTaskLogListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'logger.periodic_task_log',
        search: {
          show: true,
          placeholder: $localize`Search periodic task log ...`,
        },
        subheader: {
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.periodicTaskLogEntries;
          },
          objectName: $localize`periodic task log entry`,
          objectNamePlural: $localize`periodic task log entries`
        },
        ordering: {
          default: {
            display: $localize`Start date`,
            field: 'start_dt',
            direction: OrderingDirection.Descending,
          },
          options: [
            {display: $localize`Start date`, field: 'start_dt'},
            {display: $localize`End date`, field: 'end_dt'},
            {display: $localize`Status`, field: 'status'},
            {display: $localize`Task name`, field: 'task_name'},
          ]
        },
        filterConfig: {
          availableOptions: [
            {
              display: $localize`Start date`,
              field: 'start_dt',
              type: FilterTypes.Date
            },
            {
              display: $localize`End date`,
              field: 'end_dt',
              type: FilterTypes.Date
            },
            {
              display: $localize`Status`,
              field: 'status',
              type: FilterTypes.Choices
            },
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: ':id',
    component: PeriodicTaskLogDetailsComponent,
    resolve: {
      periodicTaskLogEntry: PeriodicTaskLogResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.periodicTaskLogEntry.task_name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class PeriodicTaskLogRoutingModule {
}
