<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

        // 调用支付方法
        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 invite(string $groupId, string $invitee): mixed
    {
        return Payment::pay($this->paymentType, ['group_id' => $groupId, 'invitee' => $invitee], $this->name);
    }

    /**
     * 获取团购信息
     */
    public function getGroupInfo(string $groupId): mixed
    {
        return Payment::query($this->paymentType, $groupId, $this->name);
    }

    /**
     * 结束团购
     */
    public function end(string $groupId): mixed
    {
        return Payment::close($this->paymentType, $groupId, $this->name);
    }
}
