"""Portfolio models — a Book is a set of capital-weighted strategy sleeves that run simultaneously.
Multiple sleeves may target the same market; the allocation logic nets them per market."""
from __future__ import annotations

from pydantic import BaseModel, ConfigDict, Field

from fxhnt.domain.models import Market, StrategySpec


class StrategyAllocation(BaseModel):
    """One sleeve of a book: a strategy on a market, given a capital weight."""
    model_config = ConfigDict(frozen=True)
    spec: StrategySpec
    market: Market
    weight: float = Field(gt=0.0)


class Book(BaseModel):
    """A named multi-strategy portfolio that is executed as one netted target."""
    name: str
    allocations: list[StrategyAllocation]
    max_gross_leverage: float = Field(default=1.0, gt=0.0)

    def markets(self) -> list[Market]:
        seen: dict[str, Market] = {}
        for a in self.allocations:
            seen[str(a.market)] = a.market
        return list(seen.values())
