import warnings


def get_integer(val=None, name="value", min_value=0, default_value=0):
    """Returns integer value from input, with basic validation

    Parameters
    ----------
    val : `float` or None, default None
        Value to convert to integer.
    name : `str`, default "value"
        What the value represents.
    min_value : `float`, default 0
        Minimum allowed value.
    default_value : `float` , default 0
        Value to be used if ``val`` is None.

    Returns
    -------
    val : `int`
        Value parsed as an integer.
    """
    if val is None:
        val = default_value
    try:
        orig = val
        val = int(val)
    except ValueError:
        raise ValueError(f"{name} must be an integer")
    else:
        if val != orig:
            warnings.warn(f"{name} converted to integer {val} from {orig}")

    if not val >= min_value:
        raise ValueError(f"{name} must be >= {min_value}")

    return val