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

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

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