import { ndmClient, userClient, type DefParameterPageQuery, type DefParameterResultVO, type DefParameterUpdateVO, type PageParams, type PageResult, type Station } from '@/apis';
import type { Result } from '@/types';
import { unwrapResponse } from '@/utils';

export const pageDefParameterApi = async (pageQuery: PageParams<DefParameterPageQuery>, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const { stationCode, signal } = options ?? {};
  const client = stationCode ? ndmClient : userClient;
  const prefix = stationCode ? `/${stationCode}` : '';
  const endpoint = `${prefix}/api/system/defParameter/page`;
  const resp = await client.post<PageResult<DefParameterResultVO>>(endpoint, pageQuery, { signal });
  const data = unwrapResponse(resp);
  return data;
};

export const updateDefParameterApi = async (updateVO: DefParameterUpdateVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const { stationCode, signal } = options ?? {};
  const client = stationCode ? ndmClient : userClient;
  const prefix = stationCode ? `/${stationCode}` : '';
  const endpoint = `${prefix}/api/system/defParameter`;
  const resp = await client.put<Result<DefParameterResultVO>>(endpoint, updateVO, { signal });
  const data = unwrapResponse(resp);
  return data;
};
