# generated by datamodel-codegen:
#   filename:  create-media-buy-response.json
#   timestamp: 2025-11-15T22:03:55+00:00

from __future__ import annotations

from typing import Annotated, Any

from adcp.types.base import AdCPBaseModel
from pydantic import AwareDatetime, ConfigDict, Field, RootModel

from . import error


class Package(AdCPBaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    buyer_ref: Annotated[str, Field(description="Buyer's reference identifier for the package")]
    package_id: Annotated[str, Field(description="Publisher's unique identifier for the package")]


class CreateMediaBuyResponse1(AdCPBaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    buyer_ref: Annotated[str, Field(description="Buyer's reference identifier for this media buy")]
    context: Annotated[
        dict[str, Any] | None,
        Field(
            description="Initiator-provided context echoed inside the task payload. Opaque metadata such as UI/session hints, correlation tokens, or tracking identifiers."
        ),
    ] = None
    creative_deadline: Annotated[
        AwareDatetime | None, Field(description="ISO 8601 timestamp for creative upload deadline")
    ] = None
    media_buy_id: Annotated[
        str, Field(description="Publisher's unique identifier for the created media buy")
    ]
    packages: Annotated[list[Package], Field(description="Array of created packages")]


class CreateMediaBuyResponse2(AdCPBaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    context: Annotated[
        dict[str, Any] | None,
        Field(
            description="Initiator-provided context echoed inside the task payload. Opaque metadata such as UI/session hints, correlation tokens, or tracking identifiers."
        ),
    ] = None
    errors: Annotated[
        list[error.Error],
        Field(description="Array of errors explaining why the operation failed", min_length=1),
    ]


class CreateMediaBuyResponse(RootModel[CreateMediaBuyResponse1 | CreateMediaBuyResponse2]):
    root: Annotated[
        CreateMediaBuyResponse1 | CreateMediaBuyResponse2,
        Field(
            description="Response payload for create_media_buy task. Returns either complete success data OR error information, never both. This enforces atomic operation semantics - the media buy is either fully created or not created at all.",
            title="Create Media Buy Response",
        ),
    ]
