import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { ListenerCreateComponent } from './listener-create/listener-create.component';
import { ListenerEditComponent } from './listener-edit/listener-edit.component';
import { ListenerDetailsComponent } from './listener-details/listener-details.component';
import { LBListenerResolver, } from '@fleio-api/openstack/load-balancing/listeners/lb-listener.resolver';
import { LBPoolsListResolver } from '@fleio-api/openstack/load-balancing/pools/lb-pools-list.resolver';
import { LBListenerCreateOptionsResolver } from '@fleio-api/openstack/load-balancing/listeners/lb-listener-create-options.resolver';
import { PolicyCreateComponent } from './policy-create/policy-create.component';
import { PolicyDetailsComponent } from './policy-details/policy-details.component';
import { LBPolicyResolver } from '@fleio-api/openstack/load-balancing/policies/lb-policy.resolver';
import { PolicyEditComponent } from './policy-edit/policy-edit.component';
import { LBPolicyCreateOptionsResolver } from '@fleio-api/openstack/load-balancing/policies/lb-policy-create-options.resolver';
import { RuleDetailsComponent } from './rule-details/rule-details.component';
import { LBRuleCreateOptionsResolver } from '@fleio-api/openstack/load-balancing/rules/lb-rule-create-options.resolver';
import { LBRuleResolver } from '@fleio-api/openstack/load-balancing/rules/lb-rule.resolver';
import { RuleEditComponent } from './rule-edit/rule-edit.component';
import { RuleCreateComponent } from './rule-create/rule-create.component';

const routes: Routes = [
  {
    path: 'create',
    component: ListenerCreateComponent,
    resolve: {
      createOptions: LBListenerCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create listener`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/policy-create',
    component: PolicyCreateComponent,
    resolve: {
      createOptions: LBPolicyCreateOptionsResolver,
      pools: LBPoolsListResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create policy`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/policy/:policyId/rule/:ruleId',
    component: RuleDetailsComponent,
    resolve: {
      createOptions: LBRuleCreateOptionsResolver,
      rule: LBRuleResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Rule details`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/policy/:policyId/rule-edit/:ruleId',
    component: RuleEditComponent,
    resolve: {
      createOptions: LBRuleCreateOptionsResolver,
      rule: LBRuleResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Edit rule`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/policy/:policyId/rule-create',
    component: RuleCreateComponent,
    resolve: {
      createOptions: LBRuleCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create rule`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/policy/:policyId',
    component: PolicyDetailsComponent,
    resolve: {
      policy: LBPolicyResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.policy.name || data.policy.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/policy-edit/:policyId',
    component: PolicyEditComponent,
    resolve: {
      policy: LBPolicyResolver,
      createOptions: LBPolicyCreateOptionsResolver,
      pools: LBPoolsListResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.policy.name || data.policy.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/edit',
    component: ListenerEditComponent,
    resolve: {
      listener: LBListenerResolver,
      pools: LBPoolsListResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.listener.name || data.listener.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id',
    component: ListenerDetailsComponent,
    resolve: {
      listener: LBListenerResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.listener.name || data.listener.id}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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