# generated by datamodel-codegen:
#   filename:  core/provenance.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 AnyUrl, AwareDatetime, ConfigDict, Field

from ..enums import digital_source_type as digital_source_type_1
from . import ext as ext_1


class AiTool(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    name: Annotated[
        str,
        Field(
            description="Name of the AI tool or model (e.g., 'DALL-E 3', 'Stable Diffusion XL', 'Gemini')"
        ),
    ]
    provider: Annotated[
        str | None,
        Field(
            description="Organization that provides the AI tool (e.g., 'OpenAI', 'Stability AI', 'Google')"
        ),
    ] = None
    version: Annotated[str | None, Field(description='Version identifier for the AI tool')] = None


class C2pa(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    manifest_url: Annotated[
        AnyUrl, Field(description='URL to the C2PA manifest store for this content')
    ]


class Role(Enum):
    creator = 'creator'
    advertiser = 'advertiser'
    agency = 'agency'
    platform = 'platform'
    tool = 'tool'


class DeclaredBy(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    agent_url: Annotated[
        AnyUrl | None,
        Field(description='URL of the agent or service that declared this provenance'),
    ] = None
    role: Annotated[Role, Field(description='Role of the declaring party in the supply chain')]


class Jurisdiction(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    country: Annotated[
        str, Field(description="ISO 3166-1 alpha-2 country code (e.g., 'US', 'DE', 'CN')")
    ]
    label_text: Annotated[
        str | None,
        Field(
            description='Required disclosure label text for this jurisdiction, in the local language'
        ),
    ] = None
    region: Annotated[
        str | None,
        Field(description="Sub-national region code (e.g., 'CA' for California, 'BY' for Bavaria)"),
    ] = None
    regulation: Annotated[
        str,
        Field(
            description="Regulation identifier (e.g., 'eu_ai_act_article_50', 'ca_sb_942', 'cn_deep_synthesis')"
        ),
    ]


class Disclosure(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    jurisdictions: Annotated[
        list[Jurisdiction] | None,
        Field(description='Jurisdictions where disclosure obligations apply', min_length=1),
    ] = None
    required: Annotated[
        bool,
        Field(
            description='Whether AI disclosure is required for this content based on applicable regulations'
        ),
    ]


class HumanOversight(Enum):
    none = 'none'
    prompt_only = 'prompt_only'
    selected = 'selected'
    edited = 'edited'
    directed = 'directed'


class Result(Enum):
    authentic = 'authentic'
    ai_generated = 'ai_generated'
    ai_modified = 'ai_modified'
    inconclusive = 'inconclusive'


class VerificationItem(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    confidence: Annotated[
        float | None,
        Field(
            description='Confidence score of the verification result (0.0 to 1.0)', ge=0.0, le=1.0
        ),
    ] = None
    details_url: Annotated[
        AnyUrl | None, Field(description='URL to the full verification report')
    ] = None
    result: Annotated[Result, Field(description='Verification outcome')]
    verified_by: Annotated[
        str,
        Field(
            description="Name of the verification service (e.g., 'DoubleVerify', 'Hive Moderation', 'Reality Defender')"
        ),
    ]
    verified_time: Annotated[
        AwareDatetime | None, Field(description='When the verification was performed (ISO 8601)')
    ] = None


class Provenance(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    ai_tool: Annotated[
        AiTool | None,
        Field(
            description='AI system used to generate or modify this content. Aligns with IPTC 2025.1 AI metadata fields and C2PA claim_generator.'
        ),
    ] = None
    c2pa: Annotated[
        C2pa | None,
        Field(
            description='C2PA Content Credentials reference. Links to the cryptographic provenance manifest for this content. Because file-level C2PA bindings break during ad-tech transcoding, this URL reference preserves the chain of provenance through the supply chain.'
        ),
    ] = None
    created_time: Annotated[
        AwareDatetime | None,
        Field(description='When this content was created or generated (ISO 8601)'),
    ] = None
    declared_by: Annotated[
        DeclaredBy | None,
        Field(
            description='Party declaring this provenance. Identifies who attached the provenance claim, enabling receiving parties to assess trust.'
        ),
    ] = None
    digital_source_type: Annotated[
        digital_source_type_1.DigitalSourceType | None,
        Field(
            description='IPTC-aligned classification of AI involvement in producing this content'
        ),
    ] = None
    disclosure: Annotated[
        Disclosure | None,
        Field(
            description='Regulatory disclosure requirements for this content. Indicates whether AI disclosure is required and under which jurisdictions.'
        ),
    ] = None
    ext: ext_1.ExtensionObject | None = None
    human_oversight: Annotated[
        HumanOversight | None,
        Field(description='Level of human involvement in the AI-assisted creation process'),
    ] = None
    verification: Annotated[
        list[VerificationItem] | None,
        Field(
            description='Third-party verification or detection results for this content. Multiple services may independently evaluate the same content. Provenance is a claim — verification results attached by the declaring party are supplementary. The enforcing party (e.g., seller/publisher) should run its own verification via get_creative_features or calibrate_content.',
            min_length=1,
        ),
    ] = None
