"""
Request/Response Schemas fuer Alerts Agent API.
"""

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


# ============================================================================
# Request Models
# ============================================================================

class AlertIngestRequest(BaseModel):
    """Request fuer manuelles Alert-Import."""
    title: str = Field(..., min_length=1, max_length=500)
    url: str = Field(..., min_length=1)
    snippet: Optional[str] = Field(default=None, max_length=2000)
    topic_label: str = Field(default="Manual Import")
    published_at: Optional[datetime] = None


class AlertRunRequest(BaseModel):
    """Request fuer Scoring-Pipeline."""
    limit: int = Field(default=50, ge=1, le=200)
    skip_scored: bool = Field(default=True)


class FeedbackRequest(BaseModel):
    """Request fuer Relevanz-Feedback."""
    alert_id: str
    is_relevant: bool
    reason: Optional[str] = None
    tags: list[str] = Field(default_factory=list)


class ProfilePriorityRequest(BaseModel):
    """Priority fuer Profile-Update."""
    label: str
    weight: float = Field(default=0.5, ge=0.0, le=1.0)
    keywords: list[str] = Field(default_factory=list)
    description: Optional[str] = None


class ProfileUpdateRequest(BaseModel):
    """Request fuer Profile-Update."""
    priorities: Optional[list[ProfilePriorityRequest]] = None
    exclusions: Optional[list[str]] = None
    policies: Optional[dict] = None


# ============================================================================
# Response Models
# ============================================================================

class AlertIngestResponse(BaseModel):
    """Response fuer Alert-Import."""
    id: str
    status: str
    message: str


class AlertRunResponse(BaseModel):
    """Response fuer Scoring-Pipeline."""
    processed: int
    keep: int
    drop: int
    review: int
    errors: int
    duration_ms: int


class InboxItem(BaseModel):
    """Ein Item in der Inbox."""
    id: str
    title: str
    url: str
    snippet: Optional[str]
    topic_label: str
    published_at: Optional[datetime]
    relevance_score: Optional[float]
    relevance_decision: Optional[str]
    relevance_summary: Optional[str]
    status: str


class InboxResponse(BaseModel):
    """Response fuer Inbox-Abfrage."""
    items: list[InboxItem]
    total: int
    page: int
    page_size: int


class FeedbackResponse(BaseModel):
    """Response fuer Feedback."""
    success: bool
    message: str
    profile_updated: bool


class ProfileResponse(BaseModel):
    """Response fuer Profile."""
    id: str
    priorities: list[dict]
    exclusions: list[str]
    policies: dict
    total_scored: int
    total_kept: int
    total_dropped: int
    accuracy_estimate: Optional[float]
