import request from '@/utils/request.js';
import { APP_TYPE } from '@/utils/env.js';

export const walletApi = {
	getDetail(identifier) {
		return request({
			url: '/api/c/v1/wallet/detail',
			method: 'GET',
			data: { identifier }
		});
	},

	recharge(identifier, amount, payment_method) {
		const data = { identifier, amount, payment_method };
		if (payment_method === 'wechat') {
			data.app_type = APP_TYPE;
		}

		return request({
			url: '/api/c/v1/wallet/recharge',
			method: 'POST',
			data
		});
	},

	rechargeCheck(identifier) {
		return request({
			url: '/api/c/v1/wallet/recharge-check',
			method: 'GET',
			data: { identifier }
		});
	},

	getRecharges(identifier, page, page_size, status) {
		return request({
			url: '/api/c/v1/wallet/recharges',
			method: 'GET',
			data: { identifier, page, page_size, status }
		});
	},

	// 新的充值订单接口
	getRechargeOrders(identifier, page, page_size, status) {
		return request({
			url: '/api/c/v1/recharge-orders',
			method: 'GET',
			data: { identifier, page, page_size, status }
		});
	},

	// 获取充值订单详情
	getRechargeOrderDetail(identifier, rechargeOrderId) {
		return request({
			url: `/api/c/v1/recharge-orders/${rechargeOrderId}`,
			method: 'GET',
			data: { identifier }
		});
	},

	getTransactions(identifier, page, page_size, params = {}) {
		return request({
			url: '/api/c/v1/wallet/transactions',
			method: 'GET',
			data: { identifier, page, page_size, ...params }
		});
	}
};
