import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { HjmGpsLog, HjmGpsLogParam } from './model';

/**
 * 分页查询黄家明_gps轨迹
 */
export async function pageHjmGpsLog(params: HjmGpsLogParam) {
  const res = await request.get<ApiResult<PageResult<HjmGpsLog>>>(
    '/hjm/hjm-gps-log/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询黄家明_gps轨迹列表
 */
export async function listHjmGpsLog(params?: HjmGpsLogParam) {
  const res = await request.get<ApiResult<HjmGpsLog[]>>(
    '/hjm/hjm-gps-log',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加黄家明_gps轨迹
 */
export async function addHjmGpsLog(data: HjmGpsLog) {
  const res = await request.post<ApiResult<unknown>>(
    '/hjm/hjm-gps-log',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改黄家明_gps轨迹
 */
export async function updateHjmGpsLog(data: HjmGpsLog) {
  const res = await request.put<ApiResult<unknown>>(
    '/hjm/hjm-gps-log',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除黄家明_gps轨迹
 */
export async function removeHjmGpsLog(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/hjm/hjm-gps-log/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除黄家明_gps轨迹
 */
export async function removeBatchHjmGpsLog(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/hjm/hjm-gps-log/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询黄家明_gps轨迹
 */
export async function getHjmGpsLog(id: number) {
  const res = await request.get<ApiResult<HjmGpsLog>>(
    '/hjm/hjm-gps-log/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
