<?php
if (!defined('ABSPATH')) {
    exit;
}

if (!function_exists('ai_content_wizard_normalize_model')) {
    function ai_content_wizard_normalize_model($model) {
        return strtolower(trim(is_string($model) ? $model : (string) $model));
    }
}

if (!function_exists('ai_content_wizard_known_openai_models')) {
    function ai_content_wizard_known_openai_models() {
        return [
            'gpt-3.5-turbo',
            'gpt-3.5-turbo-16k',
            'gpt-4',
            'gpt-4-turbo',
            'gpt-4o',
            'gpt-4o-mini',
            'gpt-4o-mini-2024-07-18',
            'gpt-4.1',
            'gpt-4.1-mini',
            'gpt-5-mini'
        ];
    }
}

if (!function_exists('ai_content_wizard_is_openai_model')) {
    function ai_content_wizard_is_openai_model($model) {
        $normalized = ai_content_wizard_normalize_model($model);
        if ($normalized === '') {
            return false;
        }

        if (in_array($normalized, ai_content_wizard_known_openai_models(), true)) {
            return true;
        }

        if (strpos($normalized, 'gpt-') === 0 || strpos($normalized, 'o1') === 0 || strpos($normalized, 'o3') === 0) {
            return true;
        }

        return false;
    }
}
