<?php

namespace EasyLinkAutomations\Auth\Platforms;

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

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

/**
 * Telegram Bot API authentication.
 *
 * Telegram uses a bot token embedded in the URL path:
 * https://api.telegram.org/bot{TOKEN}/{method}
 *
 * Test endpoint: https://api.telegram.org/bot{api_key}/getMe
 */
final class TelegramAuth implements PlatformAuthInterface
{
    public static function getSlug(): string
    {
        return 'telegram';
    }

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

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

    public static function getFields(): array
    {
        return [
            'api_key' => [
                'label'       => 'Bot Token',
                'type'        => 'text',
                'password'    => true,
                'required'    => true,
                'placeholder' => '123456789:ABCdefGhIJKlmnoPQRstuvWXyz',
                'description' => 'Your Telegram Bot API token from @BotFather',
            ],
        ];
    }

    public static function getTestRequest(): ?array
    {
        return [
            'url'    => 'https://api.telegram.org/bot{api_key}/getMe',
            'method' => 'GET',
        ];
    }

    /**
     * Telegram authenticates via the token in the URL path, not via HTTP headers.
     * The execute() methods in action classes build the URL with the token directly.
     */
    public static function authenticate(array $credentials): array
    {
        return [];
    }

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