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

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

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