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

from __future__ import annotations

from enum import Enum
from typing import Annotated, Any

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

from . import error


class Action(Enum):
    created = "created"
    updated = "updated"
    unchanged = "unchanged"
    failed = "failed"
    deleted = "deleted"


class Creative(AdCPBaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    action: Annotated[Action, Field(description="Action taken for this creative")]
    assigned_to: Annotated[
        list[str] | None,
        Field(
            description="Package IDs this creative was successfully assigned to (only present when assignments were requested)"
        ),
    ] = None
    assignment_errors: Annotated[
        dict[str, str] | None,
        Field(
            description="Assignment errors by package ID (only present when assignment failures occurred)"
        ),
    ] = None
    changes: Annotated[
        list[str] | None,
        Field(description="Field names that were modified (only present when action='updated')"),
    ] = None
    creative_id: Annotated[str, Field(description="Creative ID from the request")]
    errors: Annotated[
        list[str] | None,
        Field(description="Validation or processing errors (only present when action='failed')"),
    ] = None
    expires_at: Annotated[
        AwareDatetime | None,
        Field(
            description="ISO 8601 timestamp when preview link expires (only present when preview_url exists)"
        ),
    ] = None
    platform_id: Annotated[
        str | None, Field(description="Platform-specific ID assigned to the creative")
    ] = None
    preview_url: Annotated[
        AnyUrl | None,
        Field(
            description="Preview URL for generative creatives (only present for generative formats)"
        ),
    ] = None
    warnings: Annotated[
        list[str] | None, Field(description="Non-fatal warnings about this creative")
    ] = None


class SyncCreativesResponse1(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
    creatives: Annotated[
        list[Creative],
        Field(
            description="Results for each creative processed. Items with action='failed' indicate per-item validation/processing failures, not operation-level failures."
        ),
    ]
    dry_run: Annotated[
        bool | None, Field(description="Whether this was a dry run (no actual changes made)")
    ] = None


class SyncCreativesResponse2(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="Operation-level errors that prevented processing any creatives (e.g., authentication failure, service unavailable, invalid request format)",
            min_length=1,
        ),
    ]


class SyncCreativesResponse(RootModel[SyncCreativesResponse1 | SyncCreativesResponse2]):
    root: Annotated[
        SyncCreativesResponse1 | SyncCreativesResponse2,
        Field(
            description="Response from creative sync operation. Returns either per-creative results (best-effort processing) OR operation-level errors (complete failure). This enforces atomic semantics at the operation level while allowing per-item failures within successful operations.",
            title="Sync Creatives Response",
        ),
    ]
