import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { ApiUserListComponent } from './api-user-list/api-user-list.component';
import { ApiUserCreateComponent } from './api-user-create/api-user-create.component';
import { ApiUserDetailsComponent } from './api-user-details/api-user-details.component';
import { ApiUserEditComponent } from './api-user-edit/api-user-edit.component';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { ApiUserListResolver } from '@fleio-api/openstack/api-user/api-user-list.resolver';
import { ApiUserResolver } from '@fleio-api/openstack/api-user/api-user.resolver';
import { AuthGuard } from '@shared/auth/auth.guard';

const routes: Routes = [
  {
    path: '',
    component: ApiUserListComponent,
    resolve: {
      apiUsers: ApiUserListResolver
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.apiusers',
        getTitleDisplay: () => $localize`API users`,
        search: {
          show: false,
          placeholder: $localize`Search api users ...`,
        },
        subheader: {
          objectName: $localize`API user`,
          objectNamePlural: $localize`API users`,
          objectList: (data) => data.apiUsers as FleioObjectsList<IBaseFleioObjectModel>,
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'create',
    component: ApiUserCreateComponent,
    resolve: {},
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create API user`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: ApiUserDetailsComponent,
    resolve: {
      apiUser: ApiUserResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.apiUser.name}`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id/edit',
    component: ApiUserEditComponent,
    resolve: {
      apiUser: ApiUserResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.apiUser.name}`,
      } as IRouteConfig,
    }
  },
];

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