<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

/**
 * 金融服务支付场景类
 */
class FinancialPayment
{
    /**
     * 构造函数
     */
    public function __construct(
        protected readonly string $paymentType,
        protected readonly string $name = 'default'
    ) {}

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

        // 调用支付方法
        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 bankTransfer(array $params): mixed
    {
        // 确保参数中包含银行转账相关信息
        $params['bank_transfer'] = $params['bank_transfer'] ?? [];

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

    /**
     * 证券交易
     */
    public function securitiesTrading(array $params): mixed
    {
        // 确保参数中包含证券交易相关信息
        $params['securities'] = $params['securities'] ?? [];

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

    /**
     * 保险保费缴纳
     */
    public function insurancePremium(array $params): mixed
    {
        // 确保参数中包含保险保费缴纳相关信息
        $params['insurance'] = $params['insurance'] ?? [];

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

    /**
     * 理财产品购买
     */
    public function wealthManagement(array $params): mixed
    {
        // 确保参数中包含理财产品购买相关信息
        $params['wealth'] = $params['wealth'] ?? [];

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

    /**
     * 基金申购
     */
    public function fundPurchase(array $params): mixed
    {
        // 确保参数中包含基金申购相关信息
        $params['fund'] = $params['fund'] ?? [];

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

    /**
     * 获取金融服务支付记录
     */
    public function getFinancialRecords(string $userId): mixed
    {
        return Payment::query($this->paymentType, $userId, $this->name);
    }

    /**
     * 贷款还款
     */
    public function loanRepayment(array $params): mixed
    {
        // 确保参数中包含贷款还款相关信息
        $params['loan'] = $params['loan'] ?? [];

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