import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type {
  UserPlanIcon,
  UserPlanIconParam
} from '@/api/love/plan-icon/model';
/**
 * 分页查询价格
 */
export async function pageUserPlanIcon(params: UserPlanIconParam) {
  const res = await request.get<ApiResult<PageResult<UserPlanIcon>>>(
    '/love/user-plan-icon/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询价格列表
 */
export async function listUserPlanIcon(params?: UserPlanIconParam) {
  const res = await request.get<ApiResult<UserPlanIcon[]>>(
    '/love/user-plan-icon',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加价格
 */
export async function addUserPlanIcon(data: UserPlanIcon) {
  const res = await request.post<ApiResult<unknown>>(
    '/love/user-plan-icon',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改价格
 */
export async function updateUserPlanIcon(data: UserPlanIcon) {
  const res = await request.put<ApiResult<unknown>>(
    '/love/user-plan-icon',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 绑定价格
 */
export async function bindUserPlanIcon(data: UserPlanIcon) {
  const res = await request.put<ApiResult<unknown>>(
    '/love/user-plan-icon/bind',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量添加设备
 */
export async function addBatchUserPlanIcon(data: UserPlanIcon[]) {
  const res = await request.post<ApiResult<unknown>>(
    '/love/user-plan-icon/batch',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除价格
 */
export async function removeUserPlanIcon(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/love/user-plan-icon/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除价格
 */
export async function removeBatchUserPlanIcon(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/love/user-plan-icon/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
