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 { VolumeTypeListComponent } from './volume-type-list/volume-type-list.component';
import { VolumeTypeCreateComponent } from './volume-type-create/volume-type-create.component';
import { RegionListResolver } from '@fleio-api/openstack/region/region-list.resolver';
import { VolumeTypesListResolver } from '@fleio-api/openstack/volume/volume-types-list.resolver';
import { VolumeTypeDetailsComponent } from './volume-type-details/volume-type-details.component';
import { VolumeTypeResolver } from '@fleio-api/openstack/volume/volume-type.resolver';
import { VolumeTypePermissionsResolver } from '@fleio-api/openstack/volume/volume-type-permissions.resolver';
import { VolumeTypeEditComponent } from './volume-type-edit/volume-type-edit.component';
import { FilterTypes } from '@shared/ui-api/interfaces/route-config/filter-types';

const routes: Routes = [
  {
    path: '',
    component: VolumeTypeListComponent,
    resolve: {
      volumeTypes: VolumeTypesListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.volumes.types',
        search: {
          show: true,
          placeholder: $localize`Search volume types ...`,
        },
        subheader: {
          objectNamePlural: $localize`volume types`,
          objectName: $localize`volume types`,
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.volumeTypes;
          }
        },
        ordering: {
          default: {
            display: $localize`Date created`,
            field: 'created_at',
            direction: OrderingDirection.Descending,
          },
          options: [
            {display: $localize`Name`, field: 'name'},
            {display: $localize`Date created`, field: 'created_at'},
            {display: $localize`Date updated`, field: 'updated_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`Region`,
              field: 'region',
              type: FilterTypes.CustomModel,
              items: 'regions',
              itemsDisplayField: 'id'
            }
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: 'create',
    component: VolumeTypeCreateComponent,
    resolve: {
      regions: RegionListResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create volume type`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: VolumeTypeDetailsComponent,
    resolve: {
      volumeType: VolumeTypeResolver,
      permissions: VolumeTypePermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.volumeType.name || data.volumeType.id,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
    {
    path: ':id/edit',
    component: VolumeTypeEditComponent,
    resolve: {
      volumeType: VolumeTypeResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.volumeType.name || data.volumeType.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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