<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

/**
 * 会员充值支付场景类
 */
class MembershipRechargePayment
{
    /**
     * 构造函数
     */
    public function __construct(
        protected readonly string $paymentType,
        protected readonly string $name = 'default'
    ) {}

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

        // 调用支付方法
        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 autoRenew(string $memberId, array $params): mixed
    {
        return Payment::pay($this->paymentType, array_merge($params, ['member_id' => $memberId, 'auto_renew' => true]), $this->name);
    }

    /**
     * 取消自动续费
     */
    public function cancelAutoRenew(string $memberId): mixed
    {
        return Payment::close($this->paymentType, $memberId, $this->name);
    }

    /**
     * 获取会员信息
     */
    public function getMemberInfo(string $memberId): mixed
    {
        return Payment::query($this->paymentType, $memberId, $this->name);
    }

    /**
     * 升级会员等级
     */
    public function upgrade(string $memberId, array $params): mixed
    {
        return Payment::pay($this->paymentType, array_merge($params, ['member_id' => $memberId, 'upgrade' => true]), $this->name);
    }
}
