"""Pydantic models for email rules to ensure consistent JSON structure from LLM.""" from pydantic import BaseModel, Field from typing import List, Optional, Literal, Union class RuleCondition(BaseModel): """Represents a condition for matching emails.""" field: Literal["from", "subject", "body"] operator: Literal["contains", "equals", "starts_with"] value: Union[str, List[str]] case_sensitive: bool = False class RuleParameters(BaseModel): """Parameters for rule actions.""" folder: Optional[str] = None label: Optional[str] = None template: Optional[str] = None class RuleAction(BaseModel): """Represents an action to take on matched emails.""" type: Literal["move", "archive", "label", "draft"] parameters: RuleParameters class EmailRule(BaseModel): """Complete email rule with conditions and actions.""" rule_id: str = Field(description="Unique identifier for the rule") name: str = Field(description="Human-readable name for the rule") description: str = Field(description="Detailed description of what the rule does") conditions: List[RuleCondition] = Field(description="List of conditions that must be met") actions: List[RuleAction] = Field(description="List of actions to perform") confidence: float = Field(ge=0.0, le=1.0, description="Confidence score for the rule") class EmailRuleList(BaseModel): """List of email rules for bulk analysis.""" rules: List[EmailRule]