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

from __future__ import annotations

from typing import Annotated

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

from ..core import account as account_1
from ..core import context as context_1
from ..core import ext as ext_1
from ..core import format_id as format_id_1
from ..core import pagination_response, sub_asset
from ..core.assets import (
    audio_asset,
    brief_asset,
    catalog_asset,
    css_asset,
    daast_asset,
    html_asset,
    image_asset,
    javascript_asset,
    markdown_asset,
    text_asset,
    url_asset,
    vast_asset,
    video_asset,
    webhook_asset,
)
from ..enums import creative_status, sort_direction


class AssignedPackage(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    assigned_date: Annotated[AwareDatetime, Field(description='When this assignment was created')]
    buyer_ref: Annotated[
        str | None, Field(description="Buyer's reference identifier for this package")
    ] = None
    package_id: Annotated[str, Field(description='Package identifier')]


class Assignments(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    assigned_packages: Annotated[
        list[AssignedPackage] | None,
        Field(description='List of packages this creative is assigned to'),
    ] = None
    assignment_count: Annotated[
        int, Field(description='Total number of active package assignments', ge=0)
    ]


class Performance(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    clicks: Annotated[
        int | None, Field(description='Total clicks across all assignments', ge=0)
    ] = None
    conversion_rate: Annotated[
        float | None, Field(description='Conversion rate across all assignments', ge=0.0, le=1.0)
    ] = None
    ctr: Annotated[
        float | None, Field(description='Click-through rate (clicks/impressions)', ge=0.0, le=1.0)
    ] = None
    impressions: Annotated[
        int | None, Field(description='Total impressions across all assignments', ge=0)
    ] = None
    last_updated: Annotated[
        AwareDatetime, Field(description='When performance data was last updated')
    ]
    performance_score: Annotated[
        float | None, Field(description='Aggregated performance score (0-100)', ge=0.0, le=100.0)
    ] = None


class StatusSummary(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    approved: Annotated[int | None, Field(description='Number of approved creatives', ge=0)] = None
    archived: Annotated[int | None, Field(description='Number of archived creatives', ge=0)] = None
    pending_review: Annotated[
        int | None, Field(description='Number of creatives pending review', ge=0)
    ] = None
    processing: Annotated[
        int | None, Field(description='Number of creatives being processed', ge=0)
    ] = None
    rejected: Annotated[int | None, Field(description='Number of rejected creatives', ge=0)] = None


class SortApplied(AdCPBaseModel):
    direction: sort_direction.SortDirection | None = None
    field: str | None = None


class QuerySummary(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    filters_applied: Annotated[
        list[str] | None, Field(description='List of filters that were applied to the query')
    ] = None
    returned: Annotated[
        int | None, Field(description='Number of creatives returned in this response', ge=0)
    ] = None
    sort_applied: Annotated[
        SortApplied | None, Field(description='Sort order that was applied')
    ] = None
    total_matching: Annotated[
        int | None,
        Field(description='Total number of creatives matching filters (across all pages)', ge=0),
    ] = None


class Creative(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    account: Annotated[
        account_1.Account | None, Field(description='Account that owns this creative')
    ] = None
    assets: Annotated[
        dict[
            Annotated[str, StringConstraints(pattern=r'^[a-z0-9_]+$')],
            image_asset.ImageAsset
            | video_asset.VideoAsset
            | audio_asset.AudioAsset
            | vast_asset.VastAsset
            | text_asset.TextAsset
            | url_asset.UrlAsset
            | html_asset.HtmlAsset
            | javascript_asset.JavascriptAsset
            | webhook_asset.WebhookAsset
            | css_asset.CssAsset
            | daast_asset.DaastAsset
            | markdown_asset.MarkdownAsset
            | brief_asset.BriefAsset
            | catalog_asset.CatalogAsset,
        ]
        | None,
        Field(description='Assets for this creative, keyed by asset_id'),
    ] = None
    assignments: Annotated[
        Assignments | None,
        Field(description='Current package assignments (included when include_assignments=true)'),
    ] = None
    created_date: Annotated[
        AwareDatetime, Field(description='When the creative was uploaded to the library')
    ]
    creative_id: Annotated[str, Field(description='Unique identifier for the creative')]
    format_id: Annotated[
        format_id_1.FormatId,
        Field(description='Format identifier specifying which format this creative conforms to'),
    ]
    name: Annotated[str, Field(description='Human-readable creative name')]
    performance: Annotated[
        Performance | None,
        Field(
            description='Aggregated performance metrics (included when include_performance=true)'
        ),
    ] = None
    status: Annotated[
        creative_status.CreativeStatus, Field(description='Current approval status of the creative')
    ]
    sub_assets: Annotated[
        list[sub_asset.SubAsset] | None,
        Field(
            description='Sub-assets for multi-asset formats (included when include_sub_assets=true)'
        ),
    ] = None
    tags: Annotated[
        list[str] | None, Field(description='User-defined tags for organization and searchability')
    ] = None
    updated_date: Annotated[AwareDatetime, Field(description='When the creative was last modified')]


class ListCreativesResponse(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = None
    creatives: Annotated[
        list[Creative], Field(description='Array of creative assets matching the query')
    ]
    ext: ext_1.ExtensionObject | None = None
    format_summary: Annotated[
        dict[Annotated[str, StringConstraints(pattern=r'^[a-zA-Z0-9_-]+$')], int] | None,
        Field(description='Breakdown of creatives by format type'),
    ] = None
    pagination: pagination_response.PaginationResponse
    query_summary: Annotated[
        QuerySummary, Field(description='Summary of the query that was executed')
    ]
    sandbox: Annotated[
        bool | None,
        Field(description='When true, this response contains simulated data from sandbox mode.'),
    ] = None
    status_summary: Annotated[
        StatusSummary | None, Field(description='Breakdown of creatives by status')
    ] = None
