import pytest

from env_guard import env, require, validate
from env_guard.exceptions import (
    MissingEnvironmentVariableError,
    InvalidEnvironmentVariableError,
)


def test_missing_required_vars():
    require("TEST_VAR_1", "TEST_VAR_2")

    with pytest.raises(MissingEnvironmentVariableError):
        validate()


def test_env_with_default():
    assert env("NOT_SET", default="fallback") == "fallback"


def test_env_cast_bool_true(monkeypatch):
    monkeypatch.setenv("DEBUG", "true")
    assert env("DEBUG", cast=bool) is True


def test_env_cast_bool_invalid(monkeypatch):
    monkeypatch.setenv("DEBUG", "notabool")

    with pytest.raises(InvalidEnvironmentVariableError):
        env("DEBUG", cast=bool)