from .exceptions import ValidationError


UNITS_METRIC = "metric"
UNITS_IMPERIAL = "imperial"


class ForecastOptions(object):
    def __init__(self, days=None, units=None, lang=None):
        self.days = days
        self.units = units
        self.lang = lang


def validate_days(days):
    if days is None:
        return
    try:
        days_val = int(days)
    except (TypeError, ValueError):
        raise ValidationError("days must be an integer")
    if days_val < 1:
        raise ValidationError("days must be >= 1")


def validate_units(units):
    if units is None:
        return
    if units not in (UNITS_METRIC, UNITS_IMPERIAL):
        raise ValidationError("units must be 'metric' or 'imperial'")


def validate_lang(lang):
    if lang is None:
        return
    if not isinstance(lang, str) or not lang:
        raise ValidationError("lang must be a non-empty string")
