# generated by datamodel-codegen:
#   filename:  creative/preview_creative_response.json
#   timestamp: 2026-02-28T17:39:50+00:00

from __future__ import annotations

from typing import Annotated, Literal

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

from ..core import context as context_1
from ..core import creative_manifest, error
from ..core import ext as ext_1
from . import preview_render


class Input(AdCPBaseModel):
    context_description: Annotated[
        str | None, Field(description='Context description applied to this variant')
    ] = None
    macros: Annotated[
        dict[str, str] | None, Field(description='Macro values applied to this variant')
    ] = None
    name: Annotated[str, Field(description='Human-readable name for this variant')]


class Input4(AdCPBaseModel):
    context_description: str | None = None
    macros: dict[str, str] | None = None
    name: str


class Preview(AdCPBaseModel):
    input: Annotated[
        Input,
        Field(
            description='The input parameters that generated this preview variant. Echoes back the request input or shows defaults used.'
        ),
    ]
    preview_id: Annotated[str, Field(description='Unique identifier for this preview variant')]
    renders: Annotated[
        list[preview_render.PreviewRender],
        Field(
            description='Array of rendered pieces for this preview variant. Most formats render as a single piece. Companion ad formats (video + banner), multi-placement formats, and adaptive formats render as multiple pieces.',
            min_length=1,
        ),
    ]


class PreviewCreativeResponse1(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = None
    expires_at: Annotated[
        AwareDatetime, Field(description='ISO 8601 timestamp when preview links expire')
    ]
    ext: ext_1.ExtensionObject | None = None
    interactive_url: Annotated[
        AnyUrl | None,
        Field(
            description='Optional URL to an interactive testing page that shows all preview variants with controls to switch between them, modify macro values, and test different scenarios.'
        ),
    ] = None
    previews: Annotated[
        list[Preview],
        Field(
            description='Array of preview variants. Each preview corresponds to an input set from the request. If no inputs were provided, returns a single default preview.',
            min_length=1,
        ),
    ]
    response_type: Annotated[
        Literal['single'],
        Field(description='Discriminator indicating this is a single preview response'),
    ]


class Preview1(AdCPBaseModel):
    input: Input4
    preview_id: str
    renders: Annotated[list[preview_render.PreviewRender], Field(min_length=1)]


class Response(AdCPBaseModel):
    expires_at: Annotated[AwareDatetime, Field(description='When the preview URLs expire')]
    interactive_url: AnyUrl | None = None
    previews: Annotated[
        list[Preview1],
        Field(description='Array of preview variants for this creative', min_length=1),
    ]


class Results(AdCPBaseModel):
    creative_id: Annotated[
        str,
        Field(
            description='ID of the creative this result corresponds to. Enables correlation when processing batch results.'
        ),
    ]
    errors: Annotated[
        list[error.Error] | None, Field(description='Errors for failed requests', min_length=1)
    ] = None
    response: Annotated[Response, Field(description='Preview data for successful requests')]
    success: Annotated[Literal[True], Field(description='Indicates this preview request succeeded')]


class Preview2(Preview1):
    pass


class Response1(AdCPBaseModel):
    expires_at: Annotated[AwareDatetime, Field(description='When the preview URLs expire')]
    interactive_url: AnyUrl | None = None
    previews: Annotated[
        list[Preview2],
        Field(description='Array of preview variants for this creative', min_length=1),
    ]


class Results1(AdCPBaseModel):
    creative_id: Annotated[
        str,
        Field(
            description='ID of the creative this result corresponds to. Enables correlation when processing batch results.'
        ),
    ]
    errors: Annotated[
        list[error.Error], Field(description='Errors for failed requests', min_length=1)
    ]
    response: Annotated[
        Response1 | None, Field(description='Preview data for successful requests')
    ] = None
    success: Annotated[Literal[False], Field(description='Indicates this preview request failed')]


class PreviewCreativeResponse2(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = None
    ext: ext_1.ExtensionObject | None = None
    response_type: Annotated[
        Literal['batch'],
        Field(description='Discriminator indicating this is a batch preview response'),
    ]
    results: Annotated[
        list[Results | Results1],
        Field(
            description='Array of preview results corresponding to each request in the same order. results[0] is the result for requests[0], results[1] for requests[1], etc. Order is guaranteed even when some requests fail. Each result contains either a successful preview response or an error.',
            min_length=1,
        ),
    ]


class Preview3(AdCPBaseModel):
    preview_id: Annotated[str, Field(description='Unique identifier for this preview')]
    renders: Annotated[
        list[preview_render.PreviewRender],
        Field(description='Rendered pieces for this variant', min_length=1),
    ]


class PreviewCreativeResponse3(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = None
    creative_id: Annotated[
        str | None, Field(description='Creative identifier this variant belongs to')
    ] = None
    expires_at: Annotated[
        AwareDatetime | None, Field(description='ISO 8601 timestamp when preview links expire')
    ] = None
    ext: ext_1.ExtensionObject | None = None
    manifest: Annotated[
        creative_manifest.CreativeManifest | None,
        Field(
            description='The rendered creative manifest for this variant — the actual output that was served, not the input assets'
        ),
    ] = None
    previews: Annotated[
        list[Preview3],
        Field(
            description='Array of rendered pieces for this variant. Most formats render as a single piece.',
            min_length=1,
        ),
    ]
    response_type: Annotated[
        Literal['variant'],
        Field(description='Discriminator indicating this is a variant preview response'),
    ]
    variant_id: Annotated[str, Field(description='Platform-assigned variant identifier')]


class PreviewCreativeResponse(
    RootModel[PreviewCreativeResponse1 | PreviewCreativeResponse2 | PreviewCreativeResponse3]
):
    root: Annotated[
        PreviewCreativeResponse1 | PreviewCreativeResponse2 | PreviewCreativeResponse3,
        Field(
            description='Response containing preview links for one or more creatives. Format matches the request: single preview response for single requests, batch results for batch requests.',
            title='Preview Creative Response',
        ),
    ]
