<?php

namespace Kylin\Payment\Scenarios;

use Kylin\Payment\Payment;

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

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

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

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

    /**
     * 检查费用支付
     */
    public function examination(array $params): mixed
    {
        // 确保参数中包含检查相关信息
        $params['examination'] = $params['examination'] ?? [];

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

    /**
     * 药品费用支付
     */
    public function medication(array $params): mixed
    {
        // 确保参数中包含药品相关信息
        $params['medication'] = $params['medication'] ?? [];

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

    /**
     * 住院费用支付
     */
    public function hospitalization(array $params): mixed
    {
        // 确保参数中包含住院相关信息
        $params['hospitalization'] = $params['hospitalization'] ?? [];

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

    /**
     * 获取患者缴费记录
     */
    public function getPatientPaymentRecords(string $patientId): mixed
    {
        return Payment::query($this->paymentType, $patientId, $this->name);
    }

    /**
     * 医保报销
     */
    public function insuranceReimbursement(array $params): mixed
    {
        // 确保参数中包含医保报销相关信息
        $params['insurance'] = $params['insurance'] ?? [];

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