# generated by datamodel-codegen:
#   filename:  media_buy/sync_creatives_response.json
#   timestamp: 2026-02-23T01:56:40+00:00

from __future__ import annotations

from typing import Annotated

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

from ..core import account as account_1
from ..core import context as context_1
from ..core import error
from ..core import ext as ext_1
from ..enums import creative_action


class SyncCreativesResponse2(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = 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,
        ),
    ]
    ext: ext_1.ExtensionObject | None = None


class Creative(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    account: Annotated[
        account_1.Account | None, Field(description='Account that owns this creative')
    ] = None
    action: Annotated[
        creative_action.CreativeAction, 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[Annotated[str, StringConstraints(pattern=r'^[a-zA-Z0-9_-]+$')], 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='allow',
    )
    context: context_1.ContextObject | None = 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
    ext: ext_1.ExtensionObject | None = None
    sandbox: Annotated[
        bool | None,
        Field(description='When true, this response contains simulated data from sandbox mode.'),
    ] = None


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',
        ),
    ]
