"""Pydantic models for the notification module."""

from __future__ import annotations

import enum
from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, Field


class NotificationType(str, enum.Enum):
    """Type of notification, determines display styling."""

    INFO = "info"
    SUCCESS = "success"
    WARNING = "warning"
    ERROR = "error"


class DigestFrequency(str, enum.Enum):
    """How often the user receives digest emails."""

    NONE = "none"
    DAILY = "daily"
    WEEKLY = "weekly"


class Notification(BaseModel):
    """A single notification record."""

    id: UUID
    user_id: str
    type: NotificationType
    title: str
    message: str
    action_url: str | None = None
    read: bool = False
    created_at: datetime


class NotificationPreferences(BaseModel):
    """User notification preferences."""

    user_id: str
    email_enabled: bool = True
    in_app_enabled: bool = True
    digest_frequency: DigestFrequency = DigestFrequency.NONE


class CreateNotification(BaseModel):
    """Payload for creating a new notification."""

    user_id: str
    type: NotificationType = NotificationType.INFO
    title: str = Field(min_length=1, max_length=255)
    message: str = Field(min_length=1, max_length=2000)
    action_url: str | None = None


class UpdatePreferences(BaseModel):
    """Payload for updating notification preferences."""

    email_enabled: bool | None = None
    in_app_enabled: bool | None = None
    digest_frequency: DigestFrequency | None = None
