<?php

namespace App\Services\Payments\Gateways;

use App\Models\UserPaymentMethod;
use App\Services\Payments\Contracts\PaymentGateway;
use App\Services\Payments\GatewayResult;
use Illuminate\Support\Str;

class BankTransferGateway implements PaymentGateway
{
    public function supports(string $provider): bool
    {
        return $provider === 'rib';
    }

    public function charge(
        UserPaymentMethod $method,
        float $amount,
        string $currency,
        array $metadata = [],
    ): GatewayResult {
        return new GatewayResult(
            status: GatewayResult::STATUS_FAILED,
            message: 'RIB ne peut pas etre utilise pour un encaissement client.',
            payload: [
                'provider' => $method->provider,
                'amount' => $amount,
                'currency' => strtoupper($currency),
            ],
        );
    }

    public function payout(
        UserPaymentMethod $method,
        float $amount,
        string $currency,
        array $metadata = [],
    ): GatewayResult {
        return new GatewayResult(
            status: GatewayResult::STATUS_PENDING,
            providerReference: 'bank_po_' . Str::lower(Str::random(16)),
            message: 'Virement bancaire a traiter manuellement.',
            payload: [
                'provider' => $method->provider,
                'amount' => $amount,
                'currency' => strtoupper($currency),
                'metadata' => $metadata,
            ],
        );
    }
}
