<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

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

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

    /**
     * 外卖支付
     */
    public function takeaway(array $params): mixed
    {
        // 确保参数中包含外卖相关信息
        $params['takeaway'] = $params['takeaway'] ?? [];

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

    /**
     * 预订支付
     */
    public function reservation(array $params): mixed
    {
        // 确保参数中包含预订相关信息
        $params['reservation'] = $params['reservation'] ?? [];

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

    /**
     * 团购券支付
     */
    public function groupCoupon(array $params): mixed
    {
        // 确保参数中包含团购券相关信息
        $params['group_coupon'] = $params['group_coupon'] ?? [];

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

    /**
     * 会员卡充值
     */
    public function membershipCardRecharge(array $params): mixed
    {
        // 确保参数中包含会员卡充值相关信息
        $params['membership_card'] = $params['membership_card'] ?? [];

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

    /**
     * 获取餐饮订单记录
     */
    public function getFoodRecords(string $userId): mixed
    {
        return Payment::query($this->paymentType, $userId, $this->name);
    }

    /**
     * 扫码点餐支付
     */
    public function scanOrder(array $params): mixed
    {
        // 确保参数中包含扫码点餐相关信息
        $params['scan_order'] = $params['scan_order'] ?? [];

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