"""
Notification Schemas - Pydantic models for notification API
"""
from pydantic import BaseModel, Field
from typing import Optional, List, Any
from datetime import datetime


class NotificationBase(BaseModel):
    """Base notification schema"""
    title: str
    message: str
    notification_type: str = "info"  # info, success, warning, danger
    category: str = "system"  # system, approval, workflow, sales, inventory, etc.
    priority: str = "normal"  # low, normal, high, urgent
    action_url: Optional[str] = None
    data: Optional[str] = None


class NotificationCreate(NotificationBase):
    """Schema for creating a notification"""
    user_ids: List[str] = Field(..., description="List of user IDs to notify")
    branch_id: Optional[str] = None
    expires_at: Optional[datetime] = None


class NotificationResponse(NotificationBase):
    """Schema for notification response"""
    id: str
    read: bool = False
    read_at: Optional[str] = None
    created_at: Optional[str] = None
    expires_at: Optional[str] = None

    class Config:
        from_attributes = True


class NotificationListResponse(BaseModel):
    """Response for notification list"""
    notifications: List[NotificationResponse]
    unread_count: int
    total: int


class MarkReadRequest(BaseModel):
    """Request to mark notifications as read"""
    notification_ids: Optional[List[str]] = Field(
        None,
        description="List of notification IDs to mark as read. If empty, marks all as read."
    )


class DismissRequest(BaseModel):
    """Request to dismiss a notification"""
    notification_id: str


class PendingApprovalResponse(BaseModel):
    """Response for pending approval item"""
    id: str
    entity_type: str
    entity_id: str
    status: str
    current_state: str
    initiated_by: str
    initiated_at: Optional[str] = None
    priority: str = "normal"
    due_date: Optional[str] = None


class NotificationSummaryResponse(BaseModel):
    """Response for notification summary"""
    unread_count: int
    pending_approvals_count: int
    high_priority_count: int
    categories: dict = {}  # Count by category


class WorkflowNotificationResponse(BaseModel):
    """Response for workflow notification"""
    id: str
    subject: Optional[str] = None
    message: Optional[str] = None
    notification_type: str
    workflow_instance_id: str
    is_read: bool = False
    sent_at: Optional[str] = None
    read_at: Optional[str] = None


class NotificationPreferences(BaseModel):
    """User notification preferences"""
    email_enabled: bool = True
    in_app_enabled: bool = True
    approval_notifications: bool = True
    workflow_notifications: bool = True
    system_notifications: bool = True
    digest_frequency: str = "immediate"  # immediate, hourly, daily
