import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { FlavorListResolver } from '@fleio-api/openstack/flavor/flavor-list.resolver';
import { FlavorResolver } from '@fleio-api/openstack/flavor/flavor.resolver';
import { FlavorPermissionsResolver } from '@fleio-api/openstack/flavor/flavor-permissions.resolver';
import { FlavorCreateOptionsResolver } from '@fleio-api/openstack/flavor/flavor-create-options.resolver';
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 { FlavorListComponent } from './flavor-list/flavor-list.component';
import { FlavorCreateComponent } from './flavor-create/flavor-create.component';
import { FlavorDetailsComponent } from './flavor-details/flavor-details.component';
import { FlavorEditComponent } from './flavor-edit/flavor-edit.component';
import { ShowToClientGroupsComponent } from './show-to-client-groups/show-to-client-groups.component';
import { FlavorCloneComponent } from './flavor-clone/flavor-clone.component';

const routes: Routes = [
  {
    path: '',
    component: FlavorListComponent,
    resolve: {
      flavors: FlavorListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.flavors',
        search: {
          show: true,
          placeholder: $localize`Search flavors ...`,
        },
        subheader: {
          objectNamePlural: $localize`flavors`,
          objectName: $localize`flavor`,
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.flavors;
          }
        },
        ordering: {
          default: {
            field: 'name',
            display: $localize`Name`,
            direction: OrderingDirection.Ascending,
          },
          options: [
            {
              field: 'name',
              display: $localize`Name`,
            },
            {
              field: 'region',
              display: $localize`Region`,
            },
            {
              field: 'vcpus',
              display: $localize`vCPUs`,
            },
            {
              field: 'memory_mb',
              display: $localize`Memory MB`,
            },
            {
              field: 'root_gb',
              display: $localize`Root`,
            },
          ]
        },
        filterConfig: {
          availableOptions: [
            {
              field: 'region',
              display: $localize`Region`,
              type: FilterTypes.CustomModel,
              items: 'regions',
              itemsDisplayField: 'id'
            },
            {
              display: $localize`Memory MB`,
              field: 'memory_mb',
              type: FilterTypes.Decimal
            },
            {
              display: $localize`Root gb`,
              field: 'root_gb',
              type: FilterTypes.Decimal
            },
            {
              display: $localize`vCPUs`,
              field: 'vcpus',
              type: FilterTypes.Decimal
            },
            {
              display: $localize`Is public`,
              field: 'is_public',
              type: FilterTypes.Boolean
            },
            {
              display: $localize`Flavor group`,
              field: 'flavor_group',
              type: FilterTypes.CustomModel,
              items: 'flavorgroups',
              itemsDisplayField: 'name'
            },
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'create',
    component: FlavorCreateComponent,
    resolve: {
      createOptions: FlavorCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create flavor`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: FlavorDetailsComponent,
    resolve: {
      flavor: FlavorResolver,
      permissions: FlavorPermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.flavor.name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/show-to-client-groups',
    component: ShowToClientGroupsComponent,
    resolve: {
      flavor: FlavorResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Show flavor ${data.flavor.name} to client groups`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/edit',
    component: FlavorEditComponent,
    resolve: {
      flavor: FlavorResolver,
      createOptions: FlavorCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.flavor.name,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/clone',
    component: FlavorCloneComponent,
    resolve: {
      flavor: FlavorResolver,
      createOptions: FlavorCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Clone flavor ${data.flavor.name}`,
      } as IRouteConfig,
    }
  },
];

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