<?php

declare(strict_types=1);

namespace Itineris\GFLoqateBankVerification;

use Itineris\GFLoqateBankVerification\API\APIKeyValidator;
use Itineris\GFLoqateBankVerification\API\TransientCachedBankAccountValidator;

class SettingsFields
{
    public const SERVICE_KEY_NAME = 'loqate_bank_verification_service_key';

    public static function toArray(): array
    {
        return [
            [
                'title' => esc_html__('GF Loqate Bank Verification', 'gf-loqate-bank-verification'),
                'fields' => [
                    [
                        'name' => static::SERVICE_KEY_NAME,
                        'label' => esc_html__('Service Key', 'gf-loqate-bank-verification'),
                        'type' => 'text',
                        'input_type' => 'password',
                        'feedback_callback' => function ($value): bool {
                            if (! is_string($value) || '' === $value) {
                                return false;
                            }

                            $validator = new APIKeyValidator();
                            return $validator->isValid($value);
                        },
                        'class' => 'medium',
                        'validation_callback' => function () {
                            TransientPurger::purge(TransientCachedBankAccountValidator::TRANSIENT_KEY_PREFIX);
                        },
                    ],
                ],
            ],
        ];
    }
}

{'avg_line_length': 34.83720930232558, 'max_line_length': 110, 'alphanum_fraction': 0.4759679572763685, 'licenses': ['MIT'], 'repository_name': 'ItinerisLtd/gf-loqate-bank-verification', 'path': 'src/SettingsFields.php', 'size': 1498, 'lang': 'PHP'}