<?php

namespace Modules\Payment\Services;

use Modules\Payment\Data\PaymentRequestData;
use Modules\Payment\Data\PaymentResultData;
use Modules\Payment\Data\RefundResultData;
use Modules\Payment\Enums\PaymentMethod;
use Modules\Payment\Factories\PaymentGatewayFactory;

/**
 * Thin orchestrator delegating to the gateway resolved by
 * PaymentGatewayFactory — the single call site every Payment Action goes
 * through, so no Action ever depends on a concrete gateway class.
 */
class PaymentService
{
    public function __construct(
        private readonly PaymentGatewayFactory $gateways,
    ) {}

    public function initiate(PaymentRequestData $data): PaymentResultData
    {
        return $this->gateways->make($data->method)->initiate($data);
    }

    public function verify(PaymentMethod $method, string $gatewayTransactionId): PaymentResultData
    {
        return $this->gateways->make($method)->verify($gatewayTransactionId);
    }

    public function refund(PaymentMethod $method, string $gatewayTransactionId, string $amount, string $reason): RefundResultData
    {
        return $this->gateways->make($method)->refund($gatewayTransactionId, $amount, $reason);
    }
}
