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

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

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