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 { AuthGuard } from '@shared/auth/auth.guard';
import { HeatTemplateVersionListComponent } from './heat-template-version-list/heat-template-version-list.component';
import { HeatTemplateVersionDetailsComponent } from './heat-template-version-details/heat-template-version-details.component';
import { HeatTemplateVersionListResolver } from '@fleio-api/openstack/orchestration/heat-template-versions/heat-template-version-list.resolver';
import { HeatTemplateVersionResolver } from '@fleio-api/openstack/orchestration/heat-template-versions/heat-template-version.resolver';

const routes: Routes = [
  {
    path: '',
    component: HeatTemplateVersionListComponent,
    resolve: {
      heatTemplateVersions: HeatTemplateVersionListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.orchestration.heat-template-versions',
        getTitleDisplay: () => $localize`Heat template versions`,
        search: {
          show: true,
          placeholder: $localize`Search heat template versions ...`,
        },
        subheader: {
          objectNamePlural: $localize`heat template versions`,
          objectName: $localize`heat template version`,
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.heatTemplateVersions;
          }
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id',
    component: HeatTemplateVersionDetailsComponent,
    resolve: {
      heatTemplateVersion: HeatTemplateVersionResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.heatTemplateVersion.name}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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