<?php

declare(strict_types=1);

namespace Kylin\Pay\Shortcut\Stripe;

use Kylin\Pay\Artful\Contract\ShortcutInterface;
use Kylin\Pay\Artful\Exception\InvalidParamsException;
use Kylin\Pay\Artful\Plugin\ParserPlugin;
use Kylin\Pay\Artful\Plugin\StartPlugin;
use Kylin\Pay\Exception\Exception;
use Kylin\Pay\Plugin\Stripe\V1\AddRadarPlugin;
use Kylin\Pay\Plugin\Stripe\V1\Pay\QueryPlugin;
use Kylin\Pay\Plugin\Stripe\V1\Pay\QueryRefundPlugin;
use Kylin\Pay\Plugin\Stripe\V1\ResponsePlugin;

class QueryShortcut implements ShortcutInterface
{
    /**
     * @throws InvalidParamsException
     */
    public function getPlugins(array $params): array
    {
        $action = $params['_action'] ?? 'default';

        return match ($action) {
            'default', 'order' => $this->orderPlugins(),
            'refund' => $this->refundPlugins(),
            default => throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "不支持的 Stripe Query 操作: [{$action}]"),
        };
    }

    protected function orderPlugins(): array
    {
        return [
            StartPlugin::class,
            QueryPlugin::class,
            AddRadarPlugin::class,
            ResponsePlugin::class,
            ParserPlugin::class,
        ];
    }

    protected function refundPlugins(): array
    {
        return [
            StartPlugin::class,
            QueryRefundPlugin::class,
            AddRadarPlugin::class,
            ResponsePlugin::class,
            ParserPlugin::class,
        ];
    }
}
