import { ndmClient, userClient, type MediaServerStatus, type SendRtpInfo, type Station } from '@/apis';
import { unwrapResponse } from '@/utils';

export const getAllPushApi = async (options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const { stationCode, signal } = options ?? {};
  const client = stationCode ? ndmClient : userClient;
  const prefix = stationCode ? `/${stationCode}` : '';
  const endpoint = `${prefix}/api/ndm/ndmServiceAvailable/mediaServer/getAllPush`;
  const resp = await client.get<SendRtpInfo[]>(endpoint, { signal });
  const data = unwrapResponse(resp);
  return data;
};

export const isMediaServerAliveApi = async (options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const { stationCode, signal } = options ?? {};
  const client = stationCode ? ndmClient : userClient;
  const prefix = stationCode ? `/${stationCode}` : '';
  const endpoint = `${prefix}/api/ndm/ndmServiceAvailable/mediaServer/isAlive`;
  const resp = await client.get<MediaServerStatus[]>(endpoint, { signal });
  const data = unwrapResponse(resp);
  return data;
};

export const isSipServerAliveApi = async (options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const { stationCode, signal } = options ?? {};
  const client = stationCode ? ndmClient : userClient;
  const prefix = stationCode ? `/${stationCode}` : '';
  const endpoint = `${prefix}/api/ndm/ndmServiceAvailable/sipServer/isAlive`;
  const resp = await client.get<boolean>(endpoint, { signal });
  const data = unwrapResponse(resp);
  return data;
};
