<?php

namespace App\Services;

use App\Models\PaymentGateway;

class PaymentGatewayCredentialService
{
    public function maskedSecret(?string $secret): string
    {
        if (blank($secret)) {
            return 'Not set';
        }

        return str_repeat('*', 12).substr($secret, -4);
    }

    public function maskedCredentials(PaymentGateway $gateway): array
    {
        return [
            'secret_key' => $this->maskedSecret($gateway->secret_key),
            'webhook_secret' => $this->maskedSecret($gateway->webhook_secret),
        ];
    }

    public function decryptedCredentials(PaymentGateway $gateway): array
    {
        return [
            'public_key' => $gateway->public_key,
            'secret_key' => $gateway->secret_key,
            'webhook_secret' => $gateway->webhook_secret,
        ];
    }
}
