"""Pydantic models for EventBridge event validation and parsing. Defines the structure for adjustment_batch.initialized events received by the adjustment_file_prepare Lambda. Events follow AWS EventBridge format with detail-type routing and nested detail payloads. Event Flow: 1. UI batch creation triggers adjustment_batch.initialized event 2. EventBridge routes to Lambda based on detail-type 3. Lambda validates structure using these Pydantic models 4. Validated data (batch_id, S3 location) drives processing Models: - AdjustmentFilePrepareEvent: Top-level EventBridge structure - AdjustmentFilePrepareEventDetail: Nested detail with metadata and data - AdjustmentFilePrepareEventMetadata: Correlation ID and target entity info - AdjustmentFilePrepareEventData: S3 bucket and key for file location """ from typing import Literal, Optional from pydantic import BaseModel, ConfigDict, Field from src.enums import EventType, TargetType class AdjustmentFilePrepareEventData(BaseModel): """Business data containing S3 file location.""" model_config = ConfigDict(extra='ignore') s3_bucket: str = Field(..., description='S3 bucket name') s3_key: str = Field(..., description='S3 object key') class AdjustmentFilePrepareEventMetadata(BaseModel): """Event metadata with target entity reference and correlation ID for tracing.""" model_config = ConfigDict(extra='ignore') correlation_id: Optional[str] = Field( None, description='Correlation ID for tracing' ) target_id: int = Field( ..., gt=0, description='Primary key of target entity (must be positive)' ) target_type: Literal[TargetType.WORKSHEET_ADJUSTMENT_BATCH] = Field( ..., description='Entity type (e.g., worksheet_adjustment_batch)' ) class AdjustmentFilePrepareEventDetail(BaseModel): """EventBridge detail payload containing metadata and business data.""" model_config = ConfigDict(extra='ignore') metadata: AdjustmentFilePrepareEventMetadata = Field( ..., description='Event metadata' ) data: AdjustmentFilePrepareEventData = Field(..., description='Event business data') class AdjustmentFilePrepareEvent(BaseModel): """EventBridge event for adjustment_batch.initialized routing to Lambda.""" model_config = ConfigDict(extra='ignore', populate_by_name=True) detail_type: Literal[EventType.ADJUSTMENT_BATCH_INITIALIZED] = Field( ..., description='Event type (adjustment_batch.initialized)', alias='detail-type', ) detail: AdjustmentFilePrepareEventDetail = Field(..., description='Event details')