import {
	request
} from './http.js'
// 公共API
const apiPath = {
	getBuyPackageList: '/api/proj/servicepkg/packageinfo/listpage/${type}/self', //获取可以购买的套餐包列表
	getPayOrder: '/api/pay/get-pay', //获取支付订单
	enterprisePay: '/api/pay/pay-account-recharge/${accountRechargeId}', //企业付款完成支付
	enterpriseAccountInfo: '/api/pay/get-pay-system-bank', //获取公司账户信息
	wxPayParams: '/api/accountrecharge/save-wx-pay-prepay-id', //获取微信支付所需参数  rechargeMoney金额 packageInfoId套餐包ID
	bdPayParams: '/api/accountrecharge/save-bd-pay-order-info'
}
const proName = 'operator'
class PayApi {
	// 通用路径参数替换方法
	static #replacePathParams(path, params) {
		return Object.entries(params).reduce(
			(acc, [key, value]) => acc.replace(`{${key}}`, value),
			path
		)
	}

	// 通用请求方法
	static requestHandler(endpoint, method, data = null, pathParams = {}) {
		const path = Object.keys(pathParams).length ?
			this.#replacePathParams(endpoint, pathParams) :
			endpoint
		return request(path, method, data, proName)
	}
	static doGetBuyPackageList(type, data) {
		const path = apiPath.getBuyPackageList.replace('${type}', type);
		return request(path, "GET", data);
	}
	//对公转账完成
	static doCompleteEnterprisePay(url, data) {
		const path = apiPath.enterprisePay.replace('${accountRechargeId}', url)
		return request(path, "POST", data)
	}
	//获取账户信息
	static doGetEnterpriseAccountInfo() {
		return request(apiPath.enterpriseAccountInfo, "GET")
	}
	//获取订单
	static doGetOrder(data) {
		return request(apiPath.getPayOrder, "POST", data)
	}
	// 获取微信支付参数
	static doGetWxPayParams(data) {
		return this.requestHandler(apiPath.wxPayParams, "POST", data);
	}

	// 获取百度支付参数
	static doGetBdPayParams(data) {
		return this.requestHandler(apiPath.bdPayParams, "POST", data);
	}
}

export default PayApi;