# #region SettingsSchemas [C:3] [TYPE Module] [SEMANTICS pydantic, schema, validate, notification-channel]
# @BRIEF Pydantic schemas for application settings and automation policies.
# @LAYER Domain
# @RELATION DEPENDS_ON -> [EXT:Library:pydantic]

from datetime import datetime, time

from pydantic import BaseModel, ConfigDict, Field


# #region NotificationChannel [TYPE Class]
# @BRIEF Structured notification channel definition for policy-level custom routing.
class NotificationChannel(BaseModel):
    type: str = Field(
        ..., description="Notification channel type (e.g., SLACK, SMTP, TELEGRAM)"
    )
    target: str = Field(
        ..., description="Notification destination (e.g., #alerts, chat id, email)"
    )


# #endregion NotificationChannel


# #region ValidationPolicyBase [TYPE Class]
# @BRIEF Base schema for validation policy data.
class ValidationPolicyBase(BaseModel):
    name: str = Field(..., description="Name of the policy")
    environment_id: str = Field(..., description="Target Superset environment ID")
    is_active: bool = Field(True, description="Whether the policy is currently active")
    dashboard_ids: list[str] = Field(
        ..., description="List of dashboard IDs to validate"
    )
    schedule_days: list[int] = Field(
        ..., description="Days of the week (0-6, 0=Sunday) to run"
    )
    window_start: time = Field(..., description="Start of the execution window")
    window_end: time = Field(..., description="End of the execution window")
    notify_owners: bool = Field(
        True, description="Whether to notify dashboard owners on failure"
    )
    custom_channels: list[NotificationChannel] | None = Field(
        None,
        description="List of additional structured notification channels",
    )
    alert_condition: str = Field(
        "FAIL_ONLY",
        description="Condition to trigger alerts: FAIL_ONLY, WARN_AND_FAIL, ALWAYS",
    )


# #endregion ValidationPolicyBase


# #region ValidationPolicyCreate [TYPE Class]
# @BRIEF Schema for creating a new validation policy.
class ValidationPolicyCreate(ValidationPolicyBase):
    pass


# #endregion ValidationPolicyCreate


# #region ValidationPolicyUpdate [TYPE Class]
# @BRIEF Schema for updating an existing validation policy.
class ValidationPolicyUpdate(BaseModel):
    name: str | None = None
    environment_id: str | None = None
    is_active: bool | None = None
    dashboard_ids: list[str] | None = None
    schedule_days: list[int] | None = None
    window_start: time | None = None
    window_end: time | None = None
    notify_owners: bool | None = None
    custom_channels: list[NotificationChannel] | None = None
    alert_condition: str | None = None


# #endregion ValidationPolicyUpdate


# #region ValidationPolicyResponse [TYPE Class]
# @BRIEF Schema for validation policy response data.
class ValidationPolicyResponse(ValidationPolicyBase):
    id: str
    created_at: datetime
    updated_at: datetime

    model_config = ConfigDict(from_attributes=True)


# #endregion ValidationPolicyResponse


# #region TranslationScheduleItem [C:1] [TYPE Class]
# @BRIEF Response schema for a translation schedule item with joined job name.
class TranslationScheduleItem(BaseModel):
    schedule_id: str
    job_id: str
    job_name: str | None = None
    cron_expression: str
    timezone: str
    is_active: bool
    execution_mode: str = "full"
    last_run_at: datetime | None = None
    next_run_at: datetime | None = None
    created_by: str | None = None
    created_at: datetime | None = None

    model_config = ConfigDict(from_attributes=True)


# #endregion TranslationScheduleItem

# #endregion SettingsSchemas
