# [DEF:backend.src.schemas.settings:Module]
# @TIER: STANDARD
# @SEMANTICS: settings, schemas, pydantic, validation
# @PURPOSE: Pydantic schemas for application settings and automation policies.
# @LAYER: Domain

from pydantic import BaseModel, Field
from typing import List, Optional
from datetime import datetime, time

# [DEF:NotificationChannel:Class]
# @PURPOSE: 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)")
# [/DEF:NotificationChannel:Class]

# [DEF:ValidationPolicyBase:Class]
# @PURPOSE: 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: Optional[List[NotificationChannel]] = 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")
# [/DEF:ValidationPolicyBase:Class]

# [DEF:ValidationPolicyCreate:Class]
# @PURPOSE: Schema for creating a new validation policy.
class ValidationPolicyCreate(ValidationPolicyBase):
    pass
# [/DEF:ValidationPolicyCreate:Class]

# [DEF:ValidationPolicyUpdate:Class]
# @PURPOSE: Schema for updating an existing validation policy.
class ValidationPolicyUpdate(BaseModel):
    name: Optional[str] = None
    environment_id: Optional[str] = None
    is_active: Optional[bool] = None
    dashboard_ids: Optional[List[str]] = None
    schedule_days: Optional[List[int]] = None
    window_start: Optional[time] = None
    window_end: Optional[time] = None
    notify_owners: Optional[bool] = None
    custom_channels: Optional[List[NotificationChannel]] = None
    alert_condition: Optional[str] = None
# [/DEF:ValidationPolicyUpdate:Class]

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

    class Config:
        from_attributes = True
# [/DEF:ValidationPolicyResponse:Class]

# [/DEF:backend.src.schemas.settings:Module]