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 { HeatStackListComponent } from './heat-stack-list/heat-stack-list.component';
import { HeatStackListResolver } from '@fleio-api/openstack/orchestration/heat-stacks/heat-stack-list.resolver';
import { HeatStackCreateComponent } from './heat-stack-create/heat-stack-create.component';
import { HeatStackDetailsComponent } from './heat-stack-details/heat-stack-details.component';
import { HeatStackResolver } from '@fleio-api/openstack/orchestration/heat-stacks/heat-stack.resolver';
import { HeatStackPreviewComponent } from './heat-stack-preview/heat-stack-preview.component';
import { HeatStackChangeTemplateComponent } from './heat-stack-change-template/heat-stack-change-template.component';

const routes: Routes = [
  {
    path: '',
    component: HeatStackListComponent,
    resolve: {
      heatStacks: HeatStackListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.orchestration.heat-stacks',
        getTitleDisplay: () => $localize`Heat stacks`,
        search: {
          show: true,
          placeholder: $localize`Search heat stacks ...`,
        },
        subheader: {
          objectNamePlural: $localize`heat stacks`,
          objectName: $localize`heat stack`,
          objectList: data => data.heatStacks as FleioObjectsList<IBaseFleioObjectModel>,
        },
        ordering: {
          default: {
            display: $localize`Date created`,
            field: 'created_at',
            direction: OrderingDirection.Descending,
          },
          options: [
            {display: $localize`Stack name`, field: 'stack_name'},
            {display: $localize`Created`, field: 'created_at'},
            {display: $localize`Updated`, field: 'updated_time'},
            {display: $localize`Status`, field: 'stack_status'},
          ]
        },
        filterConfig: {
          availableOptions: [
            {
              display: $localize`Created`,
              field: 'created_at',
              type: FilterTypes.Date
            },
            {
              display: $localize`Updated`,
              field: 'updated_time',
              type: FilterTypes.Date
            },
            {
              display: $localize`Status`,
              field: 'stack_status',
              type: FilterTypes.Choices,
            },
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: 'create',
    component: HeatStackCreateComponent,
    resolve: {
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create heat stack`,
      } as IRouteConfig,
    }
  },
  {
    path: 'preview',
    component: HeatStackPreviewComponent,
    resolve: {
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Preview heat stack`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/change-template',
    component: HeatStackChangeTemplateComponent,
    resolve: {
      heatStack: HeatStackResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.heatStack.stack_name || data.heatStack.id,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: ':id',
    component: HeatStackDetailsComponent,
    resolve: {
      heatStack: HeatStackResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Heat stack ${data.heatStack.stack_name || data.heatStack.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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