import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '@shared/auth/auth.guard';
import { ContainerListComponent } from './container-list/container-list.component';
import { ContainerCreateComponent } from './container-create/container-create.component';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { ContainerListResolver } from '@fleio-api/openstack/object-store/containers/container-list.resolver';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { ContainerDetailsComponent } from './container-details/container-details.component';
import { ContainerResolver } from '@fleio-api/openstack/object-store/containers/container.resolver';
import { ContainerObjectUploadComponent } from './container-object-upload/container-object-upload.component';
import { ContainerFolderCreateComponent } from './container-folder-create/container-folder-create.component';
import { ContainerObjectCopyComponent } from './container-object-copy/container-object-copy.component';
import { ContainerEditComponent } from './container-edit/container-edit.component';
import { AccountCapabilitiesResolver } from '@fleio-api/openstack/object-store/account/account-capabilities.resolver';

const routes: Routes = [
  {
    path: '',
    component: ContainerListComponent,
    resolve: {
      containers: ContainerListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'openstack.object-store',
        getTitleDisplay: () => $localize`Object store`,
        search: {
          show: true,
          placeholder: 'Search containers ...',
        },
        subheader: {
          objectNamePlural: 'containers',
          objectName: 'container',
          showRegionSelector: true,
          regionSelectorFeature: 'openstack.object-store.show-region-select',
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.containers;
          }
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: 'create',
    component: ContainerCreateComponent,
    resolve: {
      capabilities: AccountCapabilitiesResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create container`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: ContainerDetailsComponent,
    resolve: {
      container: ContainerResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Container ${data.container.name}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/edit',
    component: ContainerEditComponent,
    resolve: {
      container: ContainerResolver,
      capabilities: AccountCapabilitiesResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit ${data.container.name}`,
      } as IRouteConfig,
    },
  },
  {
    path: ':id/object-upload',
    component: ContainerObjectUploadComponent,
    resolve: {
      container: ContainerResolver,
      capabilities: AccountCapabilitiesResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Upload file to ${data.container.name}`,
      } as IRouteConfig,
    },
  },
  {
    path: ':id/object-copy',
    component: ContainerObjectCopyComponent,
    resolve: {
      container: ContainerResolver,
      containers: ContainerListResolver,
      capabilities: AccountCapabilitiesResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Copy file from ${data.container.name}`,
      } as IRouteConfig,
    },
  },
  {
    path: ':id/folder-create',
    component: ContainerFolderCreateComponent,
    resolve: {
      container: ContainerResolver,
      capabilities: AccountCapabilitiesResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Create folder in ${data.container.name}`,
      } as IRouteConfig,
    },
  },
];

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