<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

        // 调用支付方法
        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 confirm(string $orderId): mixed
    {
        return Payment::query($this->paymentType, $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 extend(string $orderId, int $days): mixed
    {
        return Payment::pay($this->paymentType, ['order_id' => $orderId, 'extend_days' => $days], $this->name);
    }

    /**
     * 获取预售信息
     */
    public function getInfo(string $orderId): mixed
    {
        return Payment::query($this->paymentType, $orderId, $this->name);
    }
}
