from datetime import datetime, timedelta, timezone

import pytest

from src.server.models.auth import (
    AuthStatus,
    LoginRequest,
    LoginResponse,
    SessionModel,
    SetupRequest,
)


def test_login_request_validation():
    # password is required
    with pytest.raises(ValueError):
        LoginRequest(password="")

    req = LoginRequest(password="hunter2", remember=True)
    assert req.password == "hunter2"
    assert req.remember is True


def test_setup_request_requires_min_length():
    with pytest.raises(ValueError):
        SetupRequest(master_password="short")

    good = SetupRequest(master_password="longenoughpassword")
    assert good.master_password == "longenoughpassword"


def test_login_response_and_session_model():
    expires = datetime.now(timezone.utc) + timedelta(hours=1)
    lr = LoginResponse(access_token="tok", expires_at=expires)
    assert lr.token_type == "bearer"
    assert lr.access_token == "tok"

    s = SessionModel(session_id="abc123", user="admin", expires_at=expires)
    assert s.session_id == "abc123"
    assert s.user == "admin"


def test_auth_status_defaults():
    status = AuthStatus(configured=False, authenticated=False)
    assert status.configured is False
    assert status.authenticated is False
