"""Pydantic models for Lambda response and EventBridge event publishing. Defines the structure for adjustment_batch.prepared events returned by the adjustment_file_prepare Lambda. Responses follow EventBridge format and include validation results, row counts, and S3 location for downstream processing. Response Flow: 1. Lambda completes validation and staging 2. Response created with validation results and file location 3. Published to EventBridge as adjustment_batch.prepared event 4. Downstream services consume event for further processing Models: - AdjustmentFilePrepareResponse: Top-level EventBridge response structure - AdjustmentFilePrepareResponseDetail: Nested detail with metadata and data - AdjustmentFilePrepareResponseMetadata: Correlation ID and target entity info - AdjustmentFilePrepareResponseData: Validation results and S3 location """ from typing import Literal from pydantic import BaseModel, ConfigDict, Field from src.enums import EventType, TargetType class AdjustmentFilePrepareResponseData(BaseModel): """Validation results, row counts, and S3 location of prepared file.""" s3_bucket: str = Field(..., description='S3 bucket containing the prepared file') s3_key: str | None = Field(None, description='S3 key of the prepared file') valid_row_count: int = Field( ..., description='Number of rows that passed validation' ) invalid_row_count: int = Field( ..., description='Number of rows that failed validation' ) total_file_amount_multicurrency: float = Field( ..., description='Sum of all amounts from the file across currencies' ) total_rounded_amount_multicurrency: float = Field( ..., description='Sum of all rounded amounts across currencies' ) class AdjustmentFilePrepareResponseMetadata(BaseModel): """Response metadata with batch ID and correlation ID for tracing.""" correlation_id: str | None = Field(None, description='Correlation ID for tracing') target_id: int = Field(..., description='The created batch ID') target_type: Literal[TargetType.WORKSHEET_ADJUSTMENT_BATCH] = Field( ..., description='Entity type (batch)' ) class AdjustmentFilePrepareResponseDetail(BaseModel): """EventBridge detail payload containing response metadata and validation results.""" metadata: AdjustmentFilePrepareResponseMetadata = Field( ..., description='Event metadata' ) data: AdjustmentFilePrepareResponseData = Field( ..., description='Event business data' ) class AdjustmentFilePrepareResponse(BaseModel): """EventBridge response for adjustment_batch.prepared event publication.""" model_config = ConfigDict(populate_by_name=True) detail_type: Literal[EventType.ADJUSTMENT_BATCH_PREPARED] = Field( ..., description='Event type (e.g., adjustment_batch.prepared)', alias='detail-type', ) detail: AdjustmentFilePrepareResponseDetail = Field( ..., description='Event details' )