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

from __future__ import annotations

from enum import Enum
from typing import Annotated

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

from ..core import context as context_1
from ..core import error
from ..core import ext as ext_1
from ..enums import action_source as action_source_1
from ..enums import event_type


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


class ManagedBy(Enum):
    buyer = 'buyer'
    seller = 'seller'


class SnippetType(Enum):
    javascript = 'javascript'
    html = 'html'
    pixel_url = 'pixel_url'
    server_only = 'server_only'


class Setup(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    instructions: Annotated[
        str | None, Field(description='Human/agent-readable setup instructions')
    ] = None
    snippet: Annotated[
        str | None,
        Field(description='Code snippet to place on the site (JavaScript, HTML pixel, etc.)'),
    ] = None
    snippet_type: Annotated[
        SnippetType | None,
        Field(
            description="Type of implementation. 'server_only' means no client-side tag is needed."
        ),
    ] = None


class EventSource(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    action: Annotated[Action, Field(description='Action taken for this event source')]
    action_source: Annotated[
        action_source_1.ActionSource | None,
        Field(description='Type of event source (website pixel, app SDK, in-store, etc.)'),
    ] = None
    errors: Annotated[
        list[str] | None,
        Field(description="Errors for this event source (only present when action='failed')"),
    ] = None
    event_source_id: Annotated[str, Field(description='Event source ID from the request')]
    event_types: Annotated[
        list[event_type.EventType] | None, Field(description='Event types this source handles')
    ] = None
    managed_by: Annotated[
        ManagedBy | None,
        Field(
            description="Who manages this event source. 'buyer' = configured via this sync. 'seller' = always-on, managed by the seller (e.g. Amazon sales attribution for Amazon advertisers)."
        ),
    ] = None
    name: Annotated[str | None, Field(description='Name of the event source')] = None
    seller_id: Annotated[
        str | None,
        Field(
            description="Seller-assigned identifier for this event source (the ID in the seller's ad platform)"
        ),
    ] = None
    setup: Annotated[
        Setup | None,
        Field(
            description='Implementation details for activating this event source (e.g. JavaScript tag, pixel URL)'
        ),
    ] = None


class SyncEventSourcesResponse1(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = None
    event_sources: Annotated[
        list[EventSource],
        Field(
            description='Results for each event source, including both synced and seller-managed sources on the account'
        ),
    ]
    ext: ext_1.ExtensionObject | None = None
    sandbox: Annotated[
        bool | None,
        Field(description='When true, this response contains simulated data from sandbox mode.'),
    ] = None


class SyncEventSourcesResponse2(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', min_length=1),
    ]
    ext: ext_1.ExtensionObject | None = None


class SyncEventSourcesResponse(RootModel[SyncEventSourcesResponse1 | SyncEventSourcesResponse2]):
    root: Annotated[
        SyncEventSourcesResponse1 | SyncEventSourcesResponse2,
        Field(
            description='Response from event source sync operation. Returns either per-source results OR operation-level errors.',
            title='Sync Event Sources Response',
        ),
    ]
