from __future__ import annotations

from pathlib import Path

from app.core.config import settings

COMMON_PASSWORDS = frozenset(
    {
        "password",
        "password1",
        "password123",
        "12345678",
        "123456789",
        "qwerty123",
        "admin123",
        "admin1234",
        "letmein1",
        "welcome1",
        "iloveyou1",
        "sunshine1",
        "football1",
        "baseball1",
        "monkey123",
        "dragon123",
        "master123",
        "trustno1",
        "passw0rd",
        "passw0rd1",
    }
)


def load_denylist() -> set[str]:
    denylist = set(COMMON_PASSWORDS)
    path = Path(settings.password_denylist_path)
    if not path.exists():
        return denylist
    for line in path.read_text(encoding="utf-8").splitlines():
        candidate = line.strip().lower()
        if candidate and not candidate.startswith("#"):
            denylist.add(candidate)
    return denylist


def is_denied_password(password: str) -> bool:
    return password.lower() in load_denylist()
