import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type {
  Reservation,
  ReservationParam
} from '@/api/house/reservation/model';
/**
 * 分页查询用户详细资料
 */
export async function pageReservation(params: ReservationParam) {
  const res = await request.get<ApiResult<PageResult<Reservation>>>(
    '/house/reservation/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询用户详细资料列表
 */
export async function listReservation(params?: ReservationParam) {
  const res = await request.get<ApiResult<Reservation[]>>(
    '/house/reservation',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加用户详细资料
 */
export async function addReservation(data: Reservation) {
  const res = await request.post<ApiResult<unknown>>(
    '/house/reservation',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改用户详细资料
 */
export async function updateReservation(data: Reservation) {
  const res = await request.put<ApiResult<unknown>>('/house/reservation', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 绑定用户详细资料
 */
export async function bindReservation(data: Reservation) {
  const res = await request.put<ApiResult<unknown>>(
    '/house/reservation/bind',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量添加设备
 */
export async function addBatchReservation(data: Reservation[]) {
  const res = await request.post<ApiResult<unknown>>(
    '/house/reservation/batch',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除用户详细资料
 */
export async function removeReservation(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/house/reservation/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除用户详细资料
 */
export async function removeBatchReservation(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/house/reservation/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
