import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { PoolCreateComponent } from './pool-create/pool-create.component';
import { LBPoolCreateOptionsResolver } from '@fleio-api/openstack/load-balancing/pools/lb-pool-create-options.resolver';
import { PoolEditComponent } from './pool-edit/pool-edit.component';
import { LBPoolResolver } from '@fleio-api/openstack/load-balancing/pools/lb-pool.resolver';
import { PoolDetailsComponent } from './pool-details/pool-details.component';
import { HealthmonitorCreateComponent } from './healthmonitor-create/healthmonitor-create.component';
import { LBHealthMonitorCreateOptionsResolver } from '@fleio-api/openstack/load-balancing/health-monitors/lb-health-monitor-create-options.resolver';
import { LBHealthMonitorResolver } from '@fleio-api/openstack/load-balancing/health-monitors/lb-health-monitor.resolver';
import { HealthmonitorDetailsComponent } from './healthmonitor-details/healthmonitor-details.component';
import { HealthmonitorEditComponent } from './healthmonitor-edit/healthmonitor-edit.component';
import { MembersCreateComponent } from './members-create/members-create.component';
import { LBMemberCreateOptionsResolver } from '@fleio-api/openstack/load-balancing/members/lb-member-create-options.resolver';
import { MemberDetailsComponent } from './member-details/member-details.component';
import { LBMemberResolver } from '@fleio-api/openstack/load-balancing/members/lb-member.resolver';
import { MemberEditComponent } from './member-edit/member-edit.component';

const routes: Routes = [
  {
    path: 'create',
    component: PoolCreateComponent,
    resolve: {
      createOptions: LBPoolCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create pool`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/health-monitor-create',
    component: HealthmonitorCreateComponent,
    resolve: {
      pool: LBPoolResolver,
      createOptions: LBHealthMonitorCreateOptionsResolver
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create health monitor`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/health-monitor/:monitorId',
    component: HealthmonitorDetailsComponent,
    resolve: {
      pool: LBPoolResolver,
      monitor: LBHealthMonitorResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.monitor.name || data.monitor.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/health-monitor-edit/:monitorId',
    component: HealthmonitorEditComponent,
    resolve: {
      pool: LBPoolResolver,
      monitor: LBHealthMonitorResolver,
      createOptions: LBHealthMonitorCreateOptionsResolver
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.monitor.name || data.monitor.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/members-create',
    component: MembersCreateComponent,
    resolve: {
      pool: LBPoolResolver,
      createOptions: LBMemberCreateOptionsResolver
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create members`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/member/:monitorId',
    component: MemberDetailsComponent,
    resolve: {
      pool: LBPoolResolver,
      member: LBMemberResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.member.name || data.member.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/member-edit/:monitorId',
    component: MemberEditComponent,
    resolve: {
      pool: LBPoolResolver,
      member: LBMemberResolver,
      createOptions: LBMemberCreateOptionsResolver
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.member.name || data.member.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/edit',
    component: PoolEditComponent,
    resolve: {
      pool: LBPoolResolver,
      createOptions: LBPoolCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.pool.name || data.pool.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id',
    component: PoolDetailsComponent,
    resolve: {
      pool: LBPoolResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.pool.name || data.pool.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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