<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

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

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

    /**
     * 企业转账
     */
    public function transfer(array $params): mixed
    {
        // 确保参数中包含转账相关信息
        $params['transfer'] = $params['transfer'] ?? [];

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

    /**
     * 企业对账
     */
    public function reconcile(array $params): mixed
    {
        // 确保参数中包含对账相关信息
        $params['reconcile'] = $params['reconcile'] ?? [];

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

    /**
     * 获取企业账户信息
     */
    public function accountInfo(string $accountId): mixed
    {
        return Payment::query($this->paymentType, $accountId, $this->name);
    }
}
