// 退款相关接口
import { get, post } from '@/core/http/http-client'
import { buildRestPath } from '@/core/config/api-paths'

/**
 * 获取退款列表
 * page: 分页页码
 */
export async function pullRefundList({ page = 1 } = {}) {
	const { data } = await post(buildRestPath('refund/refundList'), { page })
	return {
		rows: Array.isArray(data.data) ? data.data : [],
		currentPage: data.current_page || 1,
		lastPage: data.last_page || 1,
		total: data.total || 0
	}
}

/**
 * 获取退款详情
 * id: 退款ID
 */
export async function pullRefundInfo({ id } = {}) {
	const { data } = await get(buildRestPath('refund/getRefundInfo'), { id })
	return data
}

/**
 * 申请退款
 * data: { order_id, order_type, expressType, type, reason, goods, money, images, refund_content }
 */
export async function postRefundApply(data) {
	const { data: resData } = await post(buildRestPath('refund/addApply'), data)
	return resData
}

/**
 * 编辑退款申请
 * data: { id, expressType, type, reason, price, images, refund_content }
 */
export async function postRefundEdit(data) {
	const { data: resData } = await post(buildRestPath('refund/editRefund'), data)
	return resData
}

/**
 * 关闭退款
 * id: 退款ID
 */
export async function postRefundClose({ id } = {}) {
	const { data } = await post(buildRestPath('refund/closeRefund'), { id })
	return data
}

/**
 * 平台介入
 * id: 退款ID
 */
export async function postRefundArbitration({ id } = {}) {
	const { data } = await post(buildRestPath('refund/arbitrationRefund'), { id })
	return data
}

/**
 * 提交退货物流
 * data: { id, express_no, express_name }
 */
export async function postRefundExpress(data) {
	const { data: resData } = await post(buildRestPath('refund/toExpress'), data)
	return resData
}

/**
 * 获取退款记录
 * id: 退款ID
 */
export async function pullRefundLog({ id } = {}) {
	const { data } = await get(buildRestPath('refund/getRefundLog'), { id })
	return data
}