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

export async function snapStatusApi(method: 'get', options?: { stationCode?: Station['code']; signal?: AbortSignal }): Promise<boolean>;
export async function snapStatusApi(method: 'post', options: { doSnap: boolean; stationCode?: Station['code']; signal?: AbortSignal }): Promise<boolean>;
export async function snapStatusApi(method: 'get' | 'post', options?: { doSnap?: boolean; stationCode?: Station['code']; signal?: AbortSignal }) {
  const { doSnap, stationCode, signal } = options ?? {};
  const client = stationCode ? ndmClient : userClient;
  const prefix = stationCode ? `/${stationCode}` : '';
  const endpoint = `${prefix}/api/ndm/anyTenant/snapStatus`;
  if (method === 'get') {
    const resp = await client.get<boolean>(endpoint, { signal });
    const data = unwrapResponse(resp);
    return data;
  } else {
    const resp = await client.post<boolean>(endpoint, doSnap, { signal });
    const data = unwrapResponse(resp);
    return data;
  }
}
