<?php

namespace EasyLinkAutomations\Auth\Platforms;

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

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

/**
 * Trello authentication via API key and token (query string).
 */
final class TrelloAuth implements PlatformAuthInterface
{
    public static function getSlug(): string
    {
        return 'trello';
    }

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

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

    public static function getFields(): array
    {
        return [
            'api_key' => [
                'label'       => 'API Key',
                'type'        => 'text',
                'required'    => true,
                'password'    => true,
                'description' => 'Find your API key at https://trello.com/apps/admin.',
            ],
            'api_token' => [
                'label'       => 'API Token',
                'type'        => 'text',
                'required'    => true,
                'password'    => true,
                'description' => 'Generate a read/write token using your API key: https://trello.com/1/authorize?scope=read,write&expiration=never&name=EasyLinkAutomations&key=YOUR_API_KEY&response_type=token',
            ],
        ];
    }

    public static function authenticate(array $credentials): array
    {
        // Trello uses query string authentication (key + token), not headers.
        return [];
    }

    public static function getTestRequest(): array
    {
        return [
            'url'    => 'https://api.trello.com/1/tokens/{api_token}/member?key={api_key}&token={api_token}',
            'method' => 'GET',
        ];
    }

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