/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/access-token.aurora.yaml
 */
import { type ResolveFn } from '@angular/router';
import {
  buildSortOrder,
  DEFAULT_PAGE_SIZE,
  getRelationIncludes,
  queryFindById,
  queryPaginate,
  type DataTableData,
} from '@aurora';
import { type OAuthAccessToken } from '@src/src/app/aurora.types';
import { getAccessTokenStandaloneColumns } from '../access-token.columns';
import { ACCESS_TOKEN_DETAIL_CONFIG } from './access-token.detail-config';
import { ACCESS_TOKEN_LIST_CONFIG } from './access-token.list-config';
export const accessTokenListResolver: ResolveFn<DataTableData<OAuthAccessToken>> = () => {
  const { queryPagination, paginationKey, fields } = ACCESS_TOKEN_LIST_CONFIG;
  const include = getRelationIncludes(getAccessTokenStandaloneColumns());
  return queryPaginate<OAuthAccessToken>(queryPagination, paginationKey, fields, {
    query: {
      offset: 0,
      limit: DEFAULT_PAGE_SIZE,
      order: buildSortOrder([]),
      include: include.length > 0 ? include : undefined,
    },
  });
};

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

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