<?php

namespace GriffinForms\Admin\Secure;

use GriffinForms\Includes\Integrations\Providers;

class Ai extends \GriffinForms\Admin\Secure\Settings
{
    protected function secureButlerActiveProvider($value): string
    {
        $provider = sanitize_key((string) $value);
        if ($provider === '') {
            return '';
        }

        $registered = Providers::getInstance()->getAll();
        $record = $registered[$provider] ?? null;

        if (!is_array($record) || (($record['category'] ?? '') !== 'AI')) {
            return '';
        }

        return $provider;
    }

    protected function secureButlerGenerationTimeout($value): int
    {
        $allowed = [10, 20, 30];
        $timeout = absint($value);

        if (!in_array($timeout, $allowed, true)) {
            $timeout = 20;
        }

        return $timeout;
    }

    protected function secureAiDataSharingAcknowledged($value): int
    {
        return !empty($value) ? 1 : 0;
    }
}
