import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
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 { VolumeSnapshotListResolver } from '@fleio-api/openstack/volume/volume-snapshot-list.resolver';
import { VolumeSnapshotListComponent } from './volume-snapshot-list/volume-snapshot-list.component';
import { VolumeSnapshotDetailsComponent } from './volume-snapshot-details/volume-snapshot-details.component';
import { VolumeSnapshotResolver } from '@fleio-api/openstack/volume/volume-snapshot.resolver';
import { VolumeSnapshotPermissionsResolver } from '@fleio-api/openstack/volume/volume-snapshot-permissions.resolver';

const routes: Routes = [
  {
    path: '',
    component: VolumeSnapshotListComponent,
    resolve: {
      volumeSnapshots: VolumeSnapshotListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.volumes.snapshots',
        getTitleDisplay: () => $localize`Volume snapshots`,
        search: {
          show: true,
          placeholder: $localize`Search volume snapshots ...`,
        },
        subheader: {
          objectNamePlural: $localize`volume snapshots`,
          objectName: $localize`volume snapshot`,
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.volumeSnapshots;
          }
        },
        ordering: {
          default: {
            display: $localize`Date created`,
            field: 'created_at',
            direction: OrderingDirection.Descending,
          },
          options: [
            {display: $localize`Name`, field: 'name'},
            {display: $localize`Status`, field: 'status'},
            {display: $localize`Size`, field: 'size'},
            {display: $localize`Date created`, field: 'created_at'},
          ]
        },
        filterConfig: {
          availableOptions: [
            {
              display: $localize`Created at`,
              field: 'created_at',
              type: FilterTypes.Date
            },
            {
              display: $localize`Updated at`,
              field: 'updated_at',
              type: FilterTypes.Date
            },
            {
              display: $localize`Status`,
              field: 'status',
              type: FilterTypes.Choices
            },
            {
              display: $localize`Related volume`,
              field: 'volume',
              type: FilterTypes.CustomModel,
              items: 'volumes',
              itemsDisplayField: 'name'
            },
            {
              display: $localize`Size`,
              field: 'size',
              type: FilterTypes.Decimal
            },
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id',
    component: VolumeSnapshotDetailsComponent,
    resolve: {
      volumeSnapshot: VolumeSnapshotResolver,
      permissions: VolumeSnapshotPermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.volumeSnapshot.name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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