"""ErgoBox model — IndexedErgoBox from the Ergo Node API."""

from typing import Dict, List, Optional

from pydantic import BaseModel, Field

from boxtime.models.node.asset import Asset
from boxtime.models.node.spending_proof import SpendingProof


class ErgoBox(BaseModel):
    """
    ``IndexedErgoBox`` in the spec — an ``ErgoTransactionOutput``
    extended with indexer metadata.

    Used for both outputs *and* inputs inside ``IndexedErgoTransaction``.
    """

    # ErgoTransactionOutput fields
    box_id: Optional[str] = Field(default=None, alias="boxId")
    value: int
    ergo_tree: str = Field(alias="ergoTree")
    creation_height: int = Field(alias="creationHeight")
    assets: List[Asset] = Field(default_factory=list)
    additional_registers: Dict[str, str] = Field(
        default_factory=dict, alias="additionalRegisters"
    )
    transaction_id: Optional[str] = Field(default=None, alias="transactionId")
    index: Optional[int] = Field(default=None)

    # IndexedErgoBox extensions
    address: Optional[str] = Field(default=None)
    spent_transaction_id: Optional[str] = Field(
        default=None, alias="spentTransactionId"
    )
    spending_height: Optional[int] = Field(default=None, alias="spendingHeight")
    inclusion_height: Optional[int] = Field(default=None, alias="inclusionHeight")
    global_index: Optional[int] = Field(default=None, alias="globalIndex")
    spending_proof: Optional[SpendingProof] = Field(
        default=None, alias="spendingProof"
    )
