import request from './http'


export const login = (data) => {
	return request({
		url: '/app/user/login',
		method: 'get',
		data
	})
}


export const getMyIndexInfo = (data) => {
	return request({
		url: '/app/user/userInfo',
		method: 'get',
		data,
	})
}

// 添加押金提现API
export const withdrawDeposit = (orderNo) => {
	console.log('调用提现API，订单号：', orderNo)
	return request({
		url: `/app/withdraw/add/${orderNo}`,
		method: 'get',
		hideLoading: true
	})
}

//获取所有全部订单
export const getOrderList = (data) => {
	return request({
		url: '/app/order/list',
		method: 'get',
		data,
		hideLoading: true
	})
}

//查询是否有订单
export const queryHasOrder = (deviceNo) => {
	return request({
		url: `/app/order/list?deviceNo=${deviceNo}&orderStatus=in_used`,
		method: 'get',
	})
}

// 查询指定设备号下，特定状态的订单列表
export const checkOrdersByStatus = (deviceNo, statuses) => {
	// statuses 是一个包含状态字符串的数组，例如 ['in_used', 'waiting_for_payment']
	const statusQuery = statuses.join(','); // 后端需要支持逗号分隔的状态查询
	return request({
		url: `/app/order/list?deviceNo=${deviceNo}&orderStatus=${statusQuery}`,
		method: 'get',
		hideLoading: true, // 隐藏加载提示，避免干扰用户
		ignoreEmptyError: true // 添加标记，表示即使返回空数据也不视为错误
	})
}

//设备查询
export const getDeviceInfo = (deviceNo) => {
	return request({
		url: `/app/device/${deviceNo}`,
		method: 'get',
	})
}


//创建订单
export const createOrder = (data) => {
	return request({
		url: '/app/order/add',
		method: 'post',
		data,
	})
}

//查询订单
export const queryById = (id) => {
	console.log(`查询订单详情, orderId: ${id}`)
	return request({
		url: `/app/order/${id}`,
		method: 'get',
		hideLoading: true
	})
}


//取消订单
export const cancelOrder = (data) => {
	return request({
		url: `/device/order/clear/${data.orderId}`,
		method: 'get',
		data,
	})
}


//结束订单
export const overOrderById = (orderId) => {
	console.log(`调用结束订单API, orderId: ${orderId}`)
	return request({
		url: `/app/order/close/${orderId}`,
		method: 'get',
	})
}

//立即租借
export const rentPowerBank = (deviceNo, phone) => {
	return request({
		url: '/app/device/rentPowerBank',
		method: 'post',
		data: {
			deviceNo,
			phone
		}
	})
}

//确认支付并弹出风扇
export const confirmPaymentAndRent = (orderId) => {
	console.log(`确认支付并弹出风扇, orderId: ${orderId}`)
	return request({
		url: `/app/device/confirmPaymentAndRent?orderId=${orderId}`,
		method: 'GET'
	})
}



//投诉反馈
export const addUserFeedback = (data) => {
	return request({
		url: '/app/feedback/add',
		method: 'post',
		data,
	})
}

//强制打开空格子
export const forcefOpenEmptyGrid = (deviceNo) => {
	console.log(`强制打开空格子, deviceNo: ${deviceNo}`)
	return request({
		url: `/app/device/forcef/${deviceNo}`,
		method: 'post'
	})
}

// 通过订单号获取订单信息
export const getOrderByOrderNo = (orderNo) => {
	return request({
		url: `/app/order/byOrderNo/${orderNo}`,
		method: 'get',
		hideLoading: true
	})
}
// 通过订单号获取支付分订单信息
export const getOrderByOrderNoScore = (orderNo) => {
	console.log('通过订单号获取支付分订单信息', orderNo);
	return request({
		url: `/app/wx-payment/score/create/${orderNo}`,
		method: 'get',
		hideLoading: true
	})
}

export const getOrderByOrderNoScorePayStatus = (orderNo) => {
	console.log('通过订单号获取支付分订单状态', orderNo);
	return request({
		url: `/app/wx-payment/score/status/${orderNo}`,
		method: 'get',
		hideLoading: true
	})
}

// 更新订单套餐信息
export const updateOrderPackage = (data) => {
	console.log('更新订单套餐信息：', data)
	return request({
		url: '/app/device/updateOrderPackage',
		method: 'post',
		data
	})
}

// 更新用户余额
export const updateUserBalance = (orderId) => {
	return request({
		url: `/app/user/updateBalance/${orderId}`,
		method: 'post',
		hideLoading: true
	})
}

/*
 *
 *弃用
 */
export const getPotionsDetail = (data) => {
	console.log(data);
	return request({
		url: '/device/position/positionDetails',
		method: 'get',
		data
	})
}