<?php

namespace EasyLinkAutomations\Auth\Platforms;

if (!defined('ABSPATH')) {
    exit;
}

use EasyLinkAutomations\Auth\AuthType;
use EasyLinkAutomations\Auth\Contracts\PlatformAuthInterface;

/**
 * Brevo API Key authentication.
 *
 * Uses an API key sent via the custom api-key header.
 * Test endpoint: https://api.brevo.com/v3/account
 */
final class BrevoAuth implements PlatformAuthInterface
{
    public static function getSlug(): string
    {
        return 'brevo';
    }

    public static function getName(): string
    {
        return 'Brevo';
    }

    public static function getAuthType(): string
    {
        return AuthType::API_KEY;
    }

    public static function getFields(): array
    {
        return [
            'api_key' => [
                'label'       => 'API Key',
                'type'        => 'text',
                'password'    => true,
                'required'    => true,
                'placeholder' => 'Your Brevo API Key',
            ],
        ];
    }

    public static function getTestRequest(): ?array
    {
        return [
            'url'    => 'https://api.brevo.com/v3/account',
            'method' => 'GET',
        ];
    }

    public static function authenticate(array $credentials): array
    {
        return ['api-key' => $credentials['api_key'] ?? ''];
    }

    public static function toArray(): array
    {
        return [
            'slug'      => static::getSlug(),
            'name'      => static::getName(),
            'auth_type' => static::getAuthType(),
            'fields'    => static::getFields(),
        ];
    }
}
