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

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

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