<?php
function check_for_integer(int $input) {
    return $input;
}


function hours_to_seconds_converter(int $input) {
    // Hier kannst du die Eingabe validieren, z.B. sicherstellen, dass es sich um eine gültige E-Mail-Adresse handelt.
    return minutes_to_seconds_converter($input) * 60;
}

function minutes_to_seconds_converter(int $input) {

    return check_for_integer($input) * 60;
}

function kompass_settings_validators()
{
    $slug = BDP_LV_PLUGIN_SLUG . '-limit-login-attempts';

    register_setting($slug,
        'kompass_limit_login_allowed_retries',
        'check_for_integer');

    register_setting($slug,
        'kompass_limit_login_allowed_lockouts',
        'check_for_integer');

    register_setting($slug,
        'kompass_limit_login_lockout_duration',
        'minutes_to_seconds_converter');

    register_setting($slug,
        'kompass_limit_login_long_duration',
        'hours_to_seconds_converter');

    register_setting($slug,
        'kompass_limit_login_notify_email_after',
        'check_for_integer');
}

function update_settings(array $postParams) {
    $settings = ['kompass_limit_login_lockout_duration',
        'kompass_limit_login_allowed_retries',
        'kompass_limit_login_allowed_lockouts',
        'kompass_password_minimal_strength',
        'kompass_limit_login_client_type',
        'kompass_limit_login_long_duration',
        'kompass_limit_login_lockout_notify',
        'kompass_limit_login_notify_email_after',
        'kompass_limit_login_cookies'];

    foreach ($settings as $curSetting) {
        if (isset($postParams[$curSetting])) {
            update_option($curSetting, $postParams[$curSetting]);
        } else {
            update_option($curSetting, '');
        }
    }
}