<?php

declare(strict_types=1);

namespace SiteFort\Includes;

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

class ProxyPresets {

    public const PRESET_NONE       = 'none';
    public const PRESET_CLOUDFLARE = 'cloudflare';
    public const PRESET_CUSTOM     = 'custom';

    public const VALID_PRESETS = [
        self::PRESET_NONE,
        self::PRESET_CLOUDFLARE,
        self::PRESET_CUSTOM,
    ];

    public static function get_ranges( string $preset ): array {
        if ( $preset === self::PRESET_CLOUDFLARE ) {
            if ( class_exists( '\SiteFort\Modules\Firewall\SafeNetwork\SafeNetworkRanges' ) ) {
                $ranges = \SiteFort\Modules\Firewall\SafeNetwork\SafeNetworkRanges::get_cloudflare_ranges();
                if ( $ranges !== [] ) {
                    return $ranges;
                }
            }

            return [];
        }

        return [];
    }

    public static function get_all(): array {
        return [
            self::PRESET_NONE => [
                'label'       => 'None',
                'range_count' => 0,
            ],
            self::PRESET_CLOUDFLARE => [
                'label'       => 'Cloudflare',
                'range_count' => count( self::get_ranges( self::PRESET_CLOUDFLARE ) ),
            ],
            self::PRESET_CUSTOM => [
                'label'       => 'Custom',
                'range_count' => 0,
            ],
        ];
    }

    public static function is_valid( string $preset ): bool {
        return in_array( $preset, self::VALID_PRESETS, true );
    }

}
