"""FALL-R2-WEB-01: version marker only; geometry and timing constants are fixed."""
import math

class R2ConfigError(ValueError):
    pass

def score_floor(value, minimum):
    try:valid=type(value) in (int,float) and math.isfinite(value) and 0<=value<=1
    except OverflowError:valid=False
    if not valid:raise R2ConfigError('FALL_R2_SCORE_INVALID')
    return max(float(value),minimum)

def block(value, *, request=False):
    allowed={'schema_version','reset_to_defaults'} if request else {'schema_version'}
    if type(value) is not dict or set(value)-allowed:raise R2ConfigError('FALL_R2_FIELDS_INVALID')
    if 'schema_version' not in value:raise R2ConfigError('FALL_R2_SCHEMA_VERSION_REQUIRED')
    if type(value['schema_version']) is not int or value['schema_version']!=1:raise R2ConfigError('FALL_R2_SCHEMA_VERSION_UNSUPPORTED')
    if 'reset_to_defaults' in value and value['reset_to_defaults'] is not True:raise R2ConfigError('FALL_R2_RESET_INVALID')
    return value.get('reset_to_defaults',False)
