<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

        // 调用支付方法
        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 recurring(array $params): mixed
    {
        // 确保参数中包含定期捐赠相关信息
        $params['recurring'] = $params['recurring'] ?? [];

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

    /**
     * 取消定期捐赠
     */
    public function cancelRecurring(string $donationId): mixed
    {
        return Payment::close($this->paymentType, $donationId, $this->name);
    }

    /**
     * 获取捐赠记录
     */
    public function getDonationRecords(string $userId): mixed
    {
        return Payment::query($this->paymentType, $userId, $this->name);
    }

    /**
     * 获取捐赠统计
     */
    public function getDonationStats(array $params): mixed
    {
        // 确保参数中包含统计相关信息
        $params['stats'] = $params['stats'] ?? [];

        // 调用查询方法
        return Payment::query($this->paymentType, $params, $this->name);
    }
}
