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

/**
 * 分页查询黄家明_车辆管理
 */
export async function pageHjmCar(params: HjmCarParam) {
  const res = await request.get<ApiResult<PageResult<HjmCar>>>(
    '/hjm/hjm-car/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}


/**
 * 查询黄家明_车辆管理列表
 */
export async function listHjmCar(params?: HjmCarParam) {
  const res = await request.get<ApiResult<HjmCar[]>>(
    '/hjm/hjm-car',
    {
      params
    }
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加黄家明_车辆管理
 */
export async function addHjmCar(data: HjmCar) {
  const res = await request.post<ApiResult<unknown>>(
    '/hjm/hjm-car',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改黄家明_车辆管理
 */
export async function updateHjmCar(data: HjmCar) {
  const res = await request.put<ApiResult<unknown>>(
    '/hjm/hjm-car',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除黄家明_车辆管理
 */
export async function removeHjmCar(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/hjm/hjm-car/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除黄家明_车辆管理
 */
export async function removeBatchHjmCar(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/hjm/hjm-car/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询黄家明_车辆管理
 */
export async function getHjmCar(id: number) {
  const res = await request.get<ApiResult<HjmCar>>(
    '/hjm/hjm-car/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据code查询黄家明_车辆管理
 */
export async function getHjmCarByCode(code: string) {
  const res = await request.get<ApiResult<HjmCar>>(
    '/hjm/hjm-car/getByCode/' + code
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

export async function pageByQQMap(params: HjmCarParam) {
  const res = await request.get<ApiResult<PageResult<HjmCar>>>(
    '/hjm/hjm-car/pageByQQMap',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

export async function pushSubscriptionMessages(data: any) {
  const res = await request.post<ApiResult<unknown>>(
    '/hjm/wx-subscription/send-template',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 启动mqtt服务
 */
export async function mqttStart() {
  const res = await request.get<ApiResult<unknown>>(
    '/hjm/hjm-car/mqtt'
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
