<?php

namespace GriffinForms\Includes\Payments;

use GriffinForms\Traits\Singleton;

/**
 * Resolve payment runtime services from gateway ids.
 */
class GatewayServiceResolver extends \GriffinForms\Format
{
    use Singleton;

    /**
     * Return the runtime service instance for a gateway.
     */
    public function getService(string $gateway)
    {
        $gateway = sanitize_key($gateway);

        switch ($gateway) {
            case 'stripe':
                return StripeIntentService::getInstance();
            case 'paypal':
                return PaypalOrderService::getInstance();
            default:
                $service = apply_filters('griffinforms_payment_gateway_service', null, $gateway);
                return $service;
        }
    }

    /**
     * Whether the gateway has a runtime implementation.
     */
    public function supportsGateway(string $gateway): bool
    {
        return $this->getService($gateway) !== null;
    }
}
