import { api } from "@/config";
import {
  API_GET_ALARMS,
  API_GET_GPS,
  API_PATH_ENTITIES,
  API_PATH_SHIP_TRACK_POINTS,
  API_SOS,
} from "@/constants";
import { transformEntityResponse } from "@/utils/tranform";

export async function queryGpsData() {
  return api.get<Model.GPSResponse>(API_GET_GPS);
}

export async function queryAlarm() {
  return api.get<Model.AlarmResponse>(API_GET_ALARMS);
}

export async function queryTrackPoints() {
  return api.get<Model.ShipTrackPoint[]>(API_PATH_SHIP_TRACK_POINTS);
}

export async function queryEntities(): Promise<Model.TransformedEntity[]> {
  const response = await api.get<Model.EntityResponse[]>(API_PATH_ENTITIES);
  return response.data.map(transformEntityResponse);
}

export async function queryGetSos() {
  return await api.get<Model.SosResponse>(API_SOS);
}
export async function queryDeleteSos() {
  return await api.delete<Model.SosResponse>(API_SOS);
}

export async function querySendSosMessage(message: string) {
  return await api.put<Model.SosRequest>(API_SOS, { message });
}
