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

from __future__ import annotations

from enum import Enum
from typing import Annotated, Any, Literal

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

from ..core import format_id as format_id_1
from ..core import identifier
from ..core import provenance as provenance_1


class Role(Enum):
    title = 'title'
    paragraph = 'paragraph'
    heading = 'heading'
    caption = 'caption'
    quote = 'quote'
    list_item = 'list_item'
    description = 'description'


class TranscriptSource(Enum):
    original_script = 'original_script'
    subtitles = 'subtitles'
    closed_captions = 'closed_captions'
    dub = 'dub'
    generated = 'generated'


class TranscriptSource1(Enum):
    original_script = 'original_script'
    closed_captions = 'closed_captions'
    generated = 'generated'


class Identifiers(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    apple_podcast_id: Annotated[str | None, Field(description='Apple Podcasts ID')] = None
    podcast_guid: Annotated[str | None, Field(description='Podcast GUID (from RSS feed)')] = None
    rss_url: Annotated[AnyUrl | None, Field(description='RSS feed URL')] = None
    spotify_show_id: Annotated[str | None, Field(description='Spotify show ID')] = None
    youtube_video_id: Annotated[str | None, Field(description='YouTube video ID')] = None


class Metadata(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    author: Annotated[str | None, Field(description='Artifact author name')] = None
    canonical: Annotated[AnyUrl | None, Field(description='Canonical URL')] = None
    json_ld: Annotated[
        list[dict[str, Any]] | None, Field(description='JSON-LD structured data (schema.org)')
    ] = None
    keywords: Annotated[str | None, Field(description='Artifact keywords')] = None
    open_graph: Annotated[
        dict[str, Any] | None, Field(description='Open Graph protocol metadata')
    ] = None
    twitter_card: Annotated[dict[str, Any] | None, Field(description='Twitter Card metadata')] = (
        None
    )


class AssetAccess1(AdCPBaseModel):
    method: Literal['bearer_token']
    token: Annotated[str, Field(description='OAuth2 bearer token for Authorization header')]


class Provider(Enum):
    gcp = 'gcp'
    aws = 'aws'


class AssetAccess2(AdCPBaseModel):
    credentials: Annotated[
        dict[str, Any] | None, Field(description='Service account credentials')
    ] = None
    method: Literal['service_account']
    provider: Annotated[Provider, Field(description='Cloud provider')]


class AssetAccess3(AdCPBaseModel):
    method: Literal['signed_url']


class AssetAccess(RootModel[AssetAccess1 | AssetAccess2 | AssetAccess3]):
    root: Annotated[
        AssetAccess1 | AssetAccess2 | AssetAccess3,
        Field(description='Authentication for accessing secured asset URLs'),
    ]


class Assets(AdCPBaseModel):
    content: Annotated[str, Field(description='Text content')]
    heading_level: Annotated[
        int | None, Field(description='Heading level (1-6), only for role=heading', ge=1, le=6)
    ] = None
    language: Annotated[
        str | None,
        Field(
            description="BCP 47 language tag for this text (e.g., 'en', 'es-MX'). Useful when artifact contains mixed-language content."
        ),
    ] = None
    provenance: Annotated[
        provenance_1.Provenance | None,
        Field(description='Provenance for this text block, overrides artifact-level provenance'),
    ] = None
    role: Annotated[
        Role | None,
        Field(
            description="Role of this text in the document. Use 'title' for the main artifact title, 'description' for summaries."
        ),
    ] = None
    type: Literal['text']


class Assets1(AdCPBaseModel):
    access: Annotated[AssetAccess | None, Field(description='Authentication for secured URLs')] = (
        None
    )
    alt_text: Annotated[str | None, Field(description='Alt text or image description')] = None
    caption: Annotated[str | None, Field(description='Image caption')] = None
    height: Annotated[int | None, Field(description='Image height in pixels')] = None
    provenance: Annotated[
        provenance_1.Provenance | None,
        Field(description='Provenance for this image, overrides artifact-level provenance'),
    ] = None
    type: Literal['image']
    url: Annotated[AnyUrl, Field(description='Image URL')]
    width: Annotated[int | None, Field(description='Image width in pixels')] = None


class Assets2(AdCPBaseModel):
    access: Annotated[AssetAccess | None, Field(description='Authentication for secured URLs')] = (
        None
    )
    duration_ms: Annotated[int | None, Field(description='Video duration in milliseconds')] = None
    provenance: Annotated[
        provenance_1.Provenance | None,
        Field(description='Provenance for this video, overrides artifact-level provenance'),
    ] = None
    thumbnail_url: Annotated[AnyUrl | None, Field(description='Video thumbnail URL')] = None
    transcript: Annotated[str | None, Field(description='Video transcript')] = None
    transcript_source: Annotated[
        TranscriptSource | None, Field(description='How the transcript was generated')
    ] = None
    type: Literal['video']
    url: Annotated[AnyUrl, Field(description='Video URL')]


class Assets3(AdCPBaseModel):
    access: Annotated[AssetAccess | None, Field(description='Authentication for secured URLs')] = (
        None
    )
    duration_ms: Annotated[int | None, Field(description='Audio duration in milliseconds')] = None
    provenance: Annotated[
        provenance_1.Provenance | None,
        Field(description='Provenance for this audio, overrides artifact-level provenance'),
    ] = None
    transcript: Annotated[str | None, Field(description='Audio transcript')] = None
    transcript_source: Annotated[
        TranscriptSource1 | None, Field(description='How the transcript was generated')
    ] = None
    type: Literal['audio']
    url: Annotated[AnyUrl, Field(description='Audio URL')]


class Artifact(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    artifact_id: Annotated[
        str,
        Field(
            description="Identifier for this artifact within the property. The property owner defines the scheme (e.g., 'article_12345', 'episode_42_segment_3', 'post_abc123')."
        ),
    ]
    assets: Annotated[
        list[Assets | Assets1 | Assets2 | Assets3],
        Field(
            description='Artifact assets in document flow order - text blocks, images, video, audio'
        ),
    ]
    format_id: Annotated[
        format_id_1.FormatId | None,
        Field(
            description='Optional reference to a format definition. Uses the same format registry as creative formats.'
        ),
    ] = None
    identifiers: Annotated[
        Identifiers | None, Field(description='Platform-specific identifiers for this artifact')
    ] = None
    last_update_time: Annotated[
        AwareDatetime | None,
        Field(description='When the artifact was last modified (ISO 8601 format)'),
    ] = None
    metadata: Annotated[
        Metadata | None, Field(description='Rich metadata extracted from the artifact')
    ] = None
    property_id: Annotated[
        identifier.Identifier,
        Field(description='Identifier for the property where this artifact appears'),
    ]
    provenance: Annotated[
        provenance_1.Provenance | None,
        Field(
            description='Provenance metadata for this artifact. Serves as the default provenance for all assets within this artifact — individual assets can override with their own provenance.'
        ),
    ] = None
    published_time: Annotated[
        AwareDatetime | None, Field(description='When the artifact was published (ISO 8601 format)')
    ] = None
    url: Annotated[
        AnyUrl | None,
        Field(
            description='Optional URL for this artifact (web page, podcast feed, video page). Not all artifacts have URLs (e.g., Instagram content, podcast segments, TV scenes).'
        ),
    ] = None
    variant_id: Annotated[
        str | None,
        Field(
            description="Identifies a specific variant of this artifact. Use for A/B tests, translations, or temporal versions. Examples: 'en', 'es-MX', 'v2', 'headline_test_b'. The combination of artifact_id + variant_id must be unique."
        ),
    ] = None
