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 { ClientListResolver } from '@fleio-api/client-user/client/client-list.resolver';
import { ClientCreateOptionsResolver } from '@fleio-api/client-user/client/client-create-options.resolver';
import { FilterTypes } from '@shared/ui-api/interfaces/route-config/filter-types';
import { OrderingDirection } from '@shared/ui-api/interfaces/route-config/ordering-directions';
import { AuthGuard } from '@shared/auth/auth.guard';
import { ClientListComponent } from './client-list/client-list.component';
import { ClientSendMassMessageComponent } from './client-send-mass-message/client-send-mass-message.component';

const routes: Routes = [
  {
    path: '',
    component: ClientListComponent,
    resolve: {
      clients: ClientListResolver
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'clients&users.clients',
        search: {
          show: true,
          placeholder: $localize`Search clients ...`,
        },
        subheader: {
          objectName: $localize`client`,
          objectNamePlural: $localize`clients`,
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.clients;
          }
        },
        ordering: {
          default: {
            field: 'date_created',
            direction: OrderingDirection.Descending,
            display: $localize`Date created`,
          },
          options: [
            {display: $localize`Company`, field: 'company'},
            {display: $localize`Country`, field: 'country'},
            {display: $localize`State`, field: 'state'},
            {display: $localize`Date created`, field: 'date_created'},
            {display: $localize`Up-to-date credit`, field: 'uptodate_credit'},
            {display: $localize`Configuration name`, field: 'configuration_name'},
            {display: $localize`Group name`, field: 'group_name'},
          ]
        },
        filterConfig: {
          availableOptions: [
            {
              field: 'date_created',
              display: $localize`Date created`,
              type: FilterTypes.Date
            },
            {
              display: $localize`Configuration`,
              field: 'configuration',
              type: FilterTypes.CustomModel,
              items: 'configurations',
              itemsDisplayField: 'name',
              feature: 'settings.configurations'
            },
            {
              field: 'status',
              display: $localize`Status`,
              type: FilterTypes.Choices
            },
            {
              display: $localize`Tax exempt`,
              field: 'tax_exempt',
              type: FilterTypes.Boolean
            },
            {
              display: $localize`Client group`,
              field: 'groups',
              type: FilterTypes.CustomModel,
              items: 'clientgroups',
              itemsDisplayField: 'name',
            },
            {
              display: $localize`Has instances in region`,
              field: 'services__openstack_project__instance__region',
              type: FilterTypes.CustomModel,
              items: 'regions',
              itemsDisplayField: 'id',
              feature: 'openstack'
            },
            {
              display: $localize`Has instances with flavor`,
              field: 'services__openstack_project__instance__flavor',
              type: FilterTypes.CustomModel,
              items: 'flavors',
              itemsDisplayField: 'display_name',
              feature: 'openstack'
            },
            {
              display: $localize`Has instances on hypervisor`,
              field: 'services__openstack_project__instance__host_name',
              type: FilterTypes.WildCard,
              feature: 'openstack'
            },
            {
              field: 'has_billing_agreement',
              display: $localize`Has billing agreement`,
              type: FilterTypes.Boolean
            },
            {
              field: 'has_services',
              display: $localize`Has services`,
              type: FilterTypes.Boolean
            },
            {
              field: 'has_instances',
              display: $localize`Has instances`,
              type: FilterTypes.Boolean,
              feature: 'openstack.instances'
            },
            {
              field: 'has_volumes',
              display: $localize`Has volumes`,
              type: FilterTypes.Boolean,
              feature: 'openstack.volumes'
            },
            {
              field: 'services__openstack_project__instance__image__name',
              display: $localize`Instance related image name`,
              type: FilterTypes.WildCard,
              feature: 'openstack.instances'
            },
            {
              field: 'services__product__product_type',
              display: $localize`Has service of type`,
              type: FilterTypes.Choices
            },
            {
              field: 'services__product',
              display: $localize`Has service for product`,
              type: FilterTypes.CustomModel,
              items: 'products',
              itemsDisplayField: 'name'
            }
          ]
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'send-mass-message',
    component: ClientSendMassMessageComponent,
    resolve: {
      createOptions: ClientCreateOptionsResolver
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Send mass email and/or panel notification message to clients`,
      } as IRouteConfig,
    }
  },
];

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