from enum import Enum
from typing import Union, List

from fastapi_camelcase import CamelModel
from pydantic import conint, confloat, constr


CountryCode = constr(to_lower=True, min_length=2, max_length=2)


class GenMethodEnum(str, Enum):
    rsv = "RANDOMSTREETVIEW"
    urban = "URBAN"


class RuleSetEnum(str, Enum):
    normal = "NORMAL"
    time_bank = "TIMEBANK"
    frozen = "FROZEN"
    race = "RACE"
    country_race = "COUNTRYRACE"


class GameConfig(CamelModel):
    timer: conint(gt=0)
    rounds: conint(gt=0)
    country_lock: Union[CountryCode, None] = None
    generation_method: GenMethodEnum = GenMethodEnum.rsv
    rule_set: RuleSetEnum = RuleSetEnum.normal

    class Config:
        orm_mode = True


class Guess(CamelModel):
    lat: confloat(ge=-90.0, le=90.0)
    lng: confloat(ge=-180.0, le=180.0)
    time_remaining: int
    country: Union[CountryCode, None] = None


class CacheInfo(CamelModel):
    cache_name: str
    size: int


class GeneratorInfo(CamelModel):
    generation_method: GenMethodEnum
    country_locks: List[CountryCode]
