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

from __future__ import annotations

from enum import Enum
from typing import Annotated

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

from ..core import context as context_1
from ..core import error
from ..core import ext as ext_1


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


class Status(Enum):
    processing = 'processing'
    ready = 'ready'
    too_small = 'too_small'


class Audience(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    action: Annotated[
        Action,
        Field(
            description="Action taken for this audience. 'status' is present when action is created, updated, or unchanged. 'status' is absent when action is deleted or failed."
        ),
    ]
    audience_id: Annotated[
        str, Field(description="Audience ID from the request (buyer's identifier)")
    ]
    errors: Annotated[
        list[error.Error] | None,
        Field(description="Errors for this audience (only present when action='failed')"),
    ] = None
    last_synced_at: Annotated[
        AwareDatetime | None,
        Field(
            description='ISO 8601 timestamp of when the most recent sync operation was accepted by the platform. Useful for agents reasoning about audience freshness. Omitted if the seller does not track this.'
        ),
    ] = None
    matched_count: Annotated[
        int | None,
        Field(
            description="Total members matched to platform users across all syncs (cumulative, not just this call). Populated when status is 'ready'.",
            ge=0,
        ),
    ] = None
    minimum_size: Annotated[
        int | None,
        Field(
            description="Minimum matched audience size required for targeting on this platform. Populated when status is 'too_small'. Helps agents know how many more members are needed.",
            ge=1,
        ),
    ] = None
    name: Annotated[str | None, Field(description='Name of the audience')] = None
    seller_id: Annotated[
        str | None,
        Field(description='Seller-assigned identifier for this audience in their ad platform'),
    ] = None
    status: Annotated[
        Status | None,
        Field(
            description="Matching status. Present when action is created, updated, or unchanged; absent when action is deleted or failed. 'processing': platform is still matching members against its user base. 'ready': audience is available for targeting, matched_count is populated. 'too_small': matched audience is below the platform's minimum size — add more members and re-sync."
        ),
    ] = None
    total_uploaded_count: Annotated[
        int | None,
        Field(
            description='Cumulative number of members uploaded across all syncs for this audience. Compare with matched_count to calculate match rate (matched_count / total_uploaded_count). Populated when the seller tracks cumulative upload counts.',
            ge=0,
        ),
    ] = None
    uploaded_count: Annotated[
        int | None,
        Field(
            description='Number of members submitted in this sync operation (delta, not cumulative). In discovery-only calls (no audiences array), this is 0.',
            ge=0,
        ),
    ] = None


class SyncAudiencesResponse1(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    audiences: Annotated[
        list[Audience], Field(description='Results for each audience on the account')
    ]
    context: context_1.ContextObject | None = 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 SyncAudiencesResponse2(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 SyncAudiencesResponse(RootModel[SyncAudiencesResponse1 | SyncAudiencesResponse2]):
    root: Annotated[
        SyncAudiencesResponse1 | SyncAudiencesResponse2,
        Field(
            description='Response from audience sync operation. Returns either per-audience results OR operation-level errors.',
            title='Sync Audiences Response',
        ),
    ]
