/**
 * @aurora-catalyst-generated
 * @source cliter/iam/user.aurora.yaml
 */
import { type ResolveFn } from '@angular/router';
import {
  buildSortOrder,
  DEFAULT_PAGE_SIZE,
  queryFindById,
  queryPaginate,
  type DataTableData,
} from '@aurora';
import { type IamUser } from '@src/src/app/aurora.types';
import { USER_DETAIL_CONFIG } from './user.detail-config';
import { USER_LIST_CONFIG } from './user.list-config';
export const userListResolver: ResolveFn<DataTableData<IamUser>> = () => {
  const { queryPagination, paginationKey, fields } = USER_LIST_CONFIG;
  return queryPaginate<IamUser>(queryPagination, paginationKey, fields, {
    query: {
      offset: 0,
      limit: DEFAULT_PAGE_SIZE,
      order: buildSortOrder([]),
    },
  });
};

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

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