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

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

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