"""Pydantic data models for earnings transfer.""" from __future__ import annotations from typing import Literal from pydantic import BaseModel, ConfigDict from src.enums import RateType, TransferType class ContractRef(BaseModel): """Minimal contract/account reference.""" model_config = ConfigDict(frozen=True) account_name: str = '' account_id: int | None = None contract_name: str = '' contract_id: int | None = None class TransferRecord(BaseModel): """A single transfer relationship fetched from ows-royalties.""" model_config = ConfigDict(frozen=True) # From DB (via OWS API) earnings_transfer_id: int transfer_type: TransferType rate_type: RateType = RateType.PERCENT transfer_amount: float | None = None input: str = 'closing_balance' negative: bool = False use_static_balance: bool = False # Contract parties from_contract: ContractRef to_contract: ContractRef # From Snowflake (enriched after fetch) — FROM contract balances closing_balance: float | None = None net_revenue: float | None = None gross_revenue: float | None = None # TO contract balances to_closing_balance: float | None = None to_net_revenue: float | None = None to_gross_revenue: float | None = None currency: str = '' # Adjustment metadata activity_month: int = 0 activity_year: int = 0 statement_month: int = 0 statement_year: int = 0 schedule_id: int | None = None schedule_name: str = '' from_comment: str = '' to_comment: str = '' description: str = '' status: str = '' error: str | None = None error_contract_id: int | None = None class CalculationResult(BaseModel): """Result of evaluating a single TransferRecord.""" model_config = ConfigDict(frozen=True) record: TransferRecord calculated_amount: float block_reason: str | None = None class AdjustmentRow(BaseModel): """One row in the output adjustment table.""" model_config = ConfigDict(frozen=True) side: Literal['FROM', 'TO'] earnings_transfer_id: int | None = None account_name: str = '' account_id: int | None = None contract_name: str = '' contract_id: int | None = None upc: str = '' amount: float | None = None currency: str = '' activity_month: int = 0 activity_year: int = 0 statement_month: int = 0 statement_year: int = 0 transfer_type: str = '' client_facing_comments: str = '' input_field: str = '' projected_balance: float | None = None error: str | None = None error_contract_id: int | None = None class ContractData(BaseModel): """Snowflake contract metadata and balances.""" model_config = ConfigDict(frozen=True) account_id: int | None = None account_name: str = '' contract_name: str = '' currency: str = '' closing_balance: float | None = None gross_revenue: float | None = None net_revenue: float | None = None prior_closing_balance: float | None = None