# #region TestSettingsAndHealthSchemas [TYPE Module] [C:3] [SEMANTICS test, settings, health, schema, regression]
# @RELATION BINDS_TO -> SrcRoot
# @BRIEF Regression tests for settings and health schema contracts updated in 026 fix batch.
import pytest

from pydantic import ValidationError

from src.schemas.health import DashboardHealthItem
from src.schemas.settings import ValidationPolicyCreate


# #region test_validation_policy_create_accepts_structured_custom_channels [TYPE Function]
# @RELATION BINDS_TO -> TestSettingsAndHealthSchemas
# @BRIEF Ensure policy schema accepts structured custom channel objects with type/target fields.
def test_validation_policy_create_accepts_structured_custom_channels():
    payload = {
        "name": "Daily Health",
        "environment_id": "env-1",
        "dashboard_ids": ["10", "11"],
        "schedule_days": [0, 1, 2],
        "window_start": "01:00:00",
        "window_end": "03:00:00",
        "notify_owners": True,
        "custom_channels": [{"type": "SLACK", "target": "#alerts"}],
        "alert_condition": "FAIL_ONLY",
    }
    policy = ValidationPolicyCreate(**payload)
    assert policy.custom_channels is not None
    assert len(policy.custom_channels) == 1
    assert policy.custom_channels[0].type == "SLACK"
    assert policy.custom_channels[0].target == "#alerts"
# #endregion test_validation_policy_create_accepts_structured_custom_channels
# #region test_validation_policy_create_rejects_legacy_string_custom_channels [TYPE Function]
# @RELATION BINDS_TO -> TestSettingsAndHealthSchemas
# @BRIEF Ensure legacy list[str] custom channel payload is rejected by typed channel contract.
def test_validation_policy_create_rejects_legacy_string_custom_channels():
    payload = {
        "name": "Daily Health",
        "environment_id": "env-1",
        "dashboard_ids": ["10"],
        "schedule_days": [0],
        "window_start": "01:00:00",
        "window_end": "02:00:00",
        "notify_owners": False,
        "custom_channels": ["SLACK:#alerts"],
    }
    with pytest.raises(ValidationError):
        ValidationPolicyCreate(**payload)
# #endregion test_validation_policy_create_rejects_legacy_string_custom_channels
# #region test_dashboard_health_item_status_accepts_only_whitelisted_values [TYPE Function]
# @RELATION BINDS_TO -> TestSettingsAndHealthSchemas
# @BRIEF Verify strict grouped regex only accepts PASS/WARN/FAIL/UNKNOWN exact statuses.
def test_dashboard_health_item_status_accepts_only_whitelisted_values():
    valid = DashboardHealthItem(
        dashboard_id="dash-1",
        environment_id="env-1",
        status="PASS",
        last_check="2026-03-10T10:00:00",
    )
    assert valid.status == "PASS"
    with pytest.raises(ValidationError):
        DashboardHealthItem(
            dashboard_id="dash-1",
            environment_id="env-1",
            status="PASSING",
            last_check="2026-03-10T10:00:00",
        )
    with pytest.raises(ValidationError):
        DashboardHealthItem(
            dashboard_id="dash-1",
            environment_id="env-1",
            status="FAIL ",
            last_check="2026-03-10T10:00:00",
        )
# #endregion test_dashboard_health_item_status_accepts_only_whitelisted_values
# #endregion TestSettingsAndHealthSchemas
