import pytest
from pydantic import ValidationError

from app.schemas import AdminUserPrefsUpdate


def test_valid_profile_passes():
    AdminUserPrefsUpdate(
        full_name="Frieda Schlüter", postal_code="50670",
        phone_mobile="+4915127747511", phone_landline="040 123456",
        birth_date="14.02.1976",
        emergency_contacts="a@b.de, c@d.com",
        emergency_phones="+4915127747511, 040 12345",
        location_consent=True,
    )


def test_empty_and_none_pass():
    # Leere/None-Felder gelten als konform (optional).
    AdminUserPrefsUpdate(postal_code="", phone_mobile="", birth_date="",
                         emergency_contacts="", emergency_phones=None)


@pytest.mark.parametrize("field,value", [
    ("postal_code", "123"),
    ("postal_code", "abcde"),
    ("phone_mobile", "hallo"),
    ("phone_landline", "xx"),
    ("birth_date", "1976-02-14"),
    ("birth_date", "31.02.2020"),
    ("emergency_contacts", "a@b.de, nope"),
    ("emergency_phones", "kein-telefon!!"),
])
def test_invalid_rejected(field, value):
    with pytest.raises(ValidationError):
        AdminUserPrefsUpdate(**{field: value})
