"""Step-04 → step-05 data contracts.

These dataclasses describe the IR payload that step-04 produces and step-05
consumes.  They live in ``shared`` so neither step has to reach into the
other's package.
"""
from __future__ import annotations

from dataclasses import dataclass, field

from shared.bedrock_client import get_ir_model_id, get_opus_model_id, get_react_model_id
from shared.media.images import EncodedImage
from shared.schemas.app_plan import AppPlan, PageNode
from shared.schemas.ir_bundle import IRBundle


@dataclass
class MultiPageModelConfig:
    """
    Controls which Bedrock model is used at each LLM step.

    Model allocation:
      - detection_model : Claude Opus   — called once, vision, highest-stakes decision
      - ir_model        : Claude Opus   — called N times, vision + complex JSON schema
      - react_model     : Claude Sonnet — called N times, complex TSX generation, no vision

    Defaults resolve at call-time via get_opus_model_id() / get_react_model_id() so that
    env-var overrides (BEDROCK_OPUS_MODEL_ID, BEDROCK_REACT_MODEL_ID) are respected.
    """

    detection_model: str = field(default_factory=get_opus_model_id)
    ir_model: str = field(default_factory=get_ir_model_id)
    react_model: str = field(default_factory=get_react_model_id)


@dataclass
class IRPage:
    """Intermediate representation for a single page (no React code yet)."""
    page_node: PageNode
    ir_bundle: IRBundle


@dataclass
class AppIRBundle:
    """Output of step-04: page detection + IR generation for every page."""
    app_plan: AppPlan
    ir_pages: list[IRPage]
    run_id: str
    encoded_images: list[EncodedImage] = field(default_factory=list)
