<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

/**
 * 跨境支付场景类
 */
class CrossBorderPayment
{
    /**
     * 构造函数
     */
    public function __construct(
        protected readonly string $paymentType,
        protected readonly string $name = 'default'
    ) {}

    /**
     * 创建跨境支付订单
     */
    public function create(array $params): mixed
    {
        // 确保参数中包含跨境支付相关信息
        $params['cross_border'] = $params['cross_border'] ?? [];

        // 调用支付方法
        return Payment::pay($this->paymentType, $params, $this->name);
    }

    /**
     * 支付跨境订单
     */
    public function pay(string $orderId, array $params): mixed
    {
        return Payment::pay($this->paymentType, array_merge($params, ['order_id' => $orderId]), $this->name);
    }

    /**
     * 取消跨境订单
     */
    public function cancel(string $orderId): mixed
    {
        return Payment::close($this->paymentType, $orderId, $this->name);
    }

    /**
     * 查询跨境订单状态
     */
    public function status(string $orderId): mixed
    {
        return Payment::query($this->paymentType, $orderId, $this->name);
    }

    /**
     * 跨境退款
     */
    public function refund(string $orderId, array $params): mixed
    {
        return Payment::refund($this->paymentType, array_merge($params, ['order_id' => $orderId]), $this->name);
    }

    /**
     * 跨境提现
     */
    public function withdraw(array $params): mixed
    {
        // 确保参数中包含提现相关信息
        $params['withdraw'] = $params['withdraw'] ?? [];

        // 调用支付方法
        return Payment::pay($this->paymentType, $params, $this->name);
    }

    /**
     * 汇率查询
     */
    public function exchangeRate(string $fromCurrency, string $toCurrency): mixed
    {
        return Payment::query($this->paymentType, compact('fromCurrency', 'toCurrency'), $this->name);
    }

    /**
     * 跨境结算
     */
    public function settle(array $params): mixed
    {
        // 确保参数中包含结算相关信息
        $params['settle'] = $params['settle'] ?? [];

        // 调用支付方法
        return Payment::pay($this->paymentType, $params, $this->name);
    }
}
