import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { AuthGuard } from '@shared/auth/auth.guard';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { OrderingDirection } from '@shared/ui-api/interfaces/route-config/ordering-directions';
import { RevenueReportsResolver } from '@fleio-api/utils/revenue-reports/revenue-reports.resolver';
import { RevenueReportsListComponent } from './revenue-reports-list/revenue-reports-list.component';
import { RevenueReportDetailsComponent } from './revenue-report-details/revenue-report-details.component';
import { RevenueReportResolver } from '@fleio-api/utils/revenue-reports/revenue-report.resolver';
import { RevenueReportGenerateComponent } from './revenue-report-generate/revenue-report-generate.component';
import { RevenueReportPermissionsResolver } from '@fleio-api/utils/revenue-reports/revenue-report-permissions.resolver';

const routes: Routes = [
  {
    path: '',
    component: RevenueReportsListComponent,
    resolve: {
      revenueReports: RevenueReportsResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'utils.reports',
        search: {
          show: false,
        },
        subheader: {
          objectList: (data) => data.revenueReports as FleioObjectsList<IBaseFleioObjectModel>,
          objectName: $localize`revenue report`,
          objectNamePlural: $localize`revenue reports`,
        },
        ordering: {
          default: {
            display: $localize`Start date`,
            field: 'start_date',
            direction: OrderingDirection.Descending,
          },
          options: [
            {
              display: $localize`Start date`,
              field: 'start_date',
            },
            {
              display: $localize`End date`,
              field: 'end_date',
            },
          ]
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'generate',
    component: RevenueReportGenerateComponent,
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Generate report`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: ':id',
    component: RevenueReportDetailsComponent,
    resolve: {
      revenueReport: RevenueReportResolver,
      permissions: RevenueReportPermissionsResolver
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Report for ${data.revenueReport.report_month_year}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
];

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