/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tenant-account.aurora.yaml
 */
import { type ResolveFn } from '@angular/router';
import {
  buildSortOrder,
  DEFAULT_PAGE_SIZE,
  getRelationIncludes,
  queryFindById,
  queryPaginate,
  type DataTableData,
} from '@aurora';
import { type IamTenantAccount } from '@src/src/app/aurora.types';
import { getTenantAccountStandaloneColumns } from '../tenant-account.columns';
import { TENANT_ACCOUNT_DETAIL_CONFIG } from './tenant-account.detail-config';
import { TENANT_ACCOUNT_LIST_CONFIG } from './tenant-account.list-config';
export const tenantAccountListResolver: ResolveFn<DataTableData<IamTenantAccount>> = () => {
  const { queryPagination, paginationKey, fields } = TENANT_ACCOUNT_LIST_CONFIG;
  const include = getRelationIncludes(getTenantAccountStandaloneColumns());
  return queryPaginate<IamTenantAccount>(queryPagination, paginationKey, fields, {
    query: {
      offset: 0,
      limit: DEFAULT_PAGE_SIZE,
      order: buildSortOrder([]),
      include: include.length > 0 ? include : undefined,
    },
  });
};

export const tenantAccountNewResolver: ResolveFn<boolean> = () => {
  return true;
};

export const tenantAccountDetailResolver: ResolveFn<IamTenantAccount | null> = (route) => {
  const id = route.paramMap.get('id');
  if (!id) return null;
  const { queryObject, objectKey, fields } = TENANT_ACCOUNT_DETAIL_CONFIG;
  return queryFindById<IamTenantAccount>(queryObject, objectKey, id, fields);
};
