import { RouterModule, Routes } from '@angular/router';
import { GatewayListComponent } from './gateway-list/gateway-list.component';
import { GatewayListResolver } from '@fleio-api/billing/gateways/gateway-list.resolver';
import { AuthGuard } from '@shared/auth/auth.guard';
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 { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { GatewayEditComponent } from './gateway-edit/gateway-edit.component';
import { GatewayResolver } from '@fleio-api/billing/gateways/gateway.resolver';
import { NgModule } from '@angular/core';
import { ServiceDetailsComponent } from '../services/service-details/service-details.component';
import { ServiceResolver } from '@fleio-api/billing/services/service.resolver';
import { ServicePermissionsResolver } from '@fleio-api/billing/services/service-permissions.resolver';
import { GatewayDetailsComponent } from './gateway-details/gateway-details.component';

const routes: Routes = [
  {
    path: '',
    component: GatewayListComponent,
    resolve: {
      gateways: GatewayListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'billing.gateways',
        search: {
          show: true,
          placeholder: $localize`Search gateways ...`,
        },
        subheader: {
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.gateways;
          },
          objectName: $localize`gateway`,
          objectNamePlural: $localize`gateways`,
        },
        ordering: {
          default: {
            display: $localize`Id`,
            field: 'id',
            direction: OrderingDirection.Descending,
          },
          options: [
            {
              display: $localize`Id`,
              field: 'id',
            },
            {
              display: $localize`Display name`,
              field: 'display_name',
            },
            {
              display: $localize`Enabled`,
              field: 'enabled',
            },
            {
              display: $localize`Visible to user`,
              field: 'visible_to_user',
            },
            {
              display: $localize`Fixed fee`,
              field: 'fixed_fee',
            },
            {
              display: $localize`Percent fee`,
              field: 'percent_fee',
            },
          ]
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: ':id',
    component: GatewayDetailsComponent,
    resolve: {
      gateway: GatewayResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.gateway.display_name,
      } as IRouteConfig,
    },
  },
  {
    path: ':id/edit',
    component: GatewayEditComponent,
    resolve: {
      gateway: GatewayResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit gateway ${data.gateway.display_name}`,
      } as IRouteConfig,
    }
  },
];

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