import { ProjectListComponent } from './project-list/project-list.component';
import { RouterModule, Routes } from '@angular/router';
import { ProjectListResolver } from '@fleio-api/openstack/project/project-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 { ProjectCreateComponent } from './project-create/project-create.component';
import { ProjectEditComponent } from './project-edit/project-edit.component';
import { ProjectResolver } from '@fleio-api/openstack/project/project.resolver';
import { NgModule } from '@angular/core';
import { FilterTypes } from '@shared/ui-api/interfaces/route-config/filter-types';
import { ProjectEditQuotasComponent } from './project-edit-quotas/project-edit-quotas.component';
import { ProjectQuotasCreateOptionsResolver } from '@fleio-api/openstack/project/project-quotas-create-options.resolver';
import { ProjectPermissionsResolver } from '@fleio-api/openstack/project/project-permissions.resolver';
import { ProjectDetailsComponent } from './project-details/project-details.component';

const routes: Routes = [
  {
    path: '',
    component: ProjectListComponent,
    resolve: {
      projects: ProjectListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.projects',
        search: {
          show: true,
          placeholder: $localize`Search projects ...`,
        },
        subheader: {
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.projects;
          },
          objectName: $localize`project`,
          objectNamePlural: $localize`projects`,
        },
        ordering: {
          default: {
            display: $localize`Created at`,
            field: 'created_at',
            direction: OrderingDirection.Descending,
          },
          options: [
            {
              display: $localize`Project id`,
              field: 'project_id',
            },
            {
              display: $localize`Project domain id`,
              field: 'project_domain_id',
            },
            {
              display: $localize`Disabled`,
              field: 'disabled',
            },
            {
              display: $localize`Name`,
              field: 'name',
            },
            {
              display: $localize`Created at`,
              field: 'created_at',
            },
            {
              display: $localize`Updated at`,
              field: 'updated_at',
            },
          ]
        },
        filterConfig: {
          availableOptions:[
            {
              display: $localize`Created at`,
              field: 'created_at',
              type: FilterTypes.Date,
            },
            {
              display: $localize`Updated at`,
              field: 'updated_at',
              type: FilterTypes.Date,
            },
            {
              display: $localize`Disabled`,
              field: 'disabled',
              type: FilterTypes.Boolean,
            },
            {
              display: $localize`Is domain`,
              field: 'is_domain',
              type: FilterTypes.Boolean,
            },
            {
              display: $localize`Services count`,
              field: 'services_count',
              type: FilterTypes.Decimal,
            },
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'create',
    component: ProjectCreateComponent,
    resolve: {
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create project`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/edit-quotas',
    component: ProjectEditQuotasComponent,
    resolve: {
      project: ProjectResolver,
      createOptions: ProjectQuotasCreateOptionsResolver,
      permissions: ProjectPermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit project ${data.project.name} quotas`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: ProjectDetailsComponent,
    resolve: {
      project: ProjectResolver,
      permissions: ProjectPermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.project.name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/edit',
    component: ProjectEditComponent,
    resolve: {
      project: ProjectResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit project ${data.project.name}`,
      } as IRouteConfig,
    }
  },
];

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