<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

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

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

    /**
     * 运费险购买
     */
    public function shippingInsurance(array $params): mixed
    {
        // 确保参数中包含运费险购买相关信息
        $params['shipping_insurance'] = $params['shipping_insurance'] ?? [];

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

    /**
     * 物流增值服务
     */
    public function valueAddedService(array $params): mixed
    {
        // 确保参数中包含物流增值服务相关信息
        $params['value_added'] = $params['value_added'] ?? [];

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

    /**
     * 国际物流支付
     */
    public function internationalShipping(array $params): mixed
    {
        // 确保参数中包含国际物流相关信息
        $params['international'] = $params['international'] ?? [];

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

    /**
     * 物流押金支付
     */
    public function deposit(array $params): mixed
    {
        // 确保参数中包含物流押金相关信息
        $params['deposit'] = $params['deposit'] ?? [];

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

    /**
     * 获取物流支付记录
     */
    public function getLogisticsRecords(string $userId): mixed
    {
        return Payment::query($this->paymentType, $userId, $this->name);
    }

    /**
     * 批量物流支付
     */
    public function batch(array $params): mixed
    {
        // 确保参数中包含批量物流支付相关信息
        $params['batch'] = $params['batch'] ?? [];

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