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

from __future__ import annotations

from typing import Annotated

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

from ..enums import metro_system, postal_system
from . import ext as ext_1
from . import offering_asset_group


class Country(RootModel[str]):
    root: Annotated[str, Field(pattern='^[A-Z]{2}$')]


class Metro(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    system: Annotated[
        metro_system.MetroAreaSystem,
        Field(description="Metro area classification system (e.g., 'nielsen_dma', 'uk_itl2')"),
    ]
    values: Annotated[list[str], Field(description='Metro codes within the system', min_length=1)]


class Region(RootModel[str]):
    root: Annotated[str, Field(pattern='^[A-Z]{2}-[A-Z0-9]{1,3}$')]


class PostalArea(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    system: Annotated[
        postal_system.PostalCodeSystem,
        Field(description="Postal code system (e.g., 'us_zip', 'de_plz')"),
    ]
    values: Annotated[list[str], Field(description='Postal codes within the system', min_length=1)]


class GeoTargets(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    countries: Annotated[
        list[Country] | None,
        Field(
            description="Countries where this offering is relevant. ISO 3166-1 alpha-2 codes (e.g., 'US', 'NL', 'DE').",
            min_length=1,
        ),
    ] = None
    metros: Annotated[
        list[Metro] | None,
        Field(
            description='Metro areas where this offering is relevant. Each entry specifies the classification system and target values.',
            min_length=1,
        ),
    ] = None
    postal_areas: Annotated[
        list[PostalArea] | None,
        Field(
            description='Postal areas where this offering is relevant. Each entry specifies the postal system and target values.',
            min_length=1,
        ),
    ] = None
    regions: Annotated[
        list[Region] | None,
        Field(
            description="Regions or states where this offering is relevant. ISO 3166-2 subdivision codes (e.g., 'NL-NH', 'US-CA').",
            min_length=1,
        ),
    ] = None


class Offering(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    assets: Annotated[
        list[offering_asset_group.OfferingAssetGroup] | None,
        Field(
            description='Structured asset groups for this offering. Each group carries a typed pool of creative assets (headlines, images, videos, etc.) identified by a group ID that matches format-level vocabulary.'
        ),
    ] = None
    categories: Annotated[
        list[str] | None,
        Field(
            description="Categories this offering belongs to (e.g., 'measurement', 'identity', 'programmatic')"
        ),
    ] = None
    checkout_url: Annotated[
        AnyUrl | None,
        Field(
            description="URL for checkout/purchase flow when the brand doesn't support agentic checkout."
        ),
    ] = None
    description: Annotated[str | None, Field(description="Description of what's being offered")] = (
        None
    )
    ext: ext_1.ExtensionObject | None = None
    geo_targets: Annotated[
        GeoTargets | None,
        Field(
            description="Geographic scope of this offering. Declares where the offering is relevant — for location-specific offerings such as job vacancies, in-store promotions, or local events. Platforms use this to target geographically appropriate audiences and to filter out offerings irrelevant to a user's location. Uses the same geographic structures as targeting_overlay in create_media_buy."
        ),
    ] = None
    keywords: Annotated[
        list[str] | None,
        Field(
            description='Keywords for matching this offering to user intent. Hosts use these for retrieval/relevance scoring.'
        ),
    ] = None
    landing_url: Annotated[
        AnyUrl | None,
        Field(
            description="Landing page URL for this offering. For catalog-driven creatives, this is the per-item click-through destination that platforms map to the ad's link-out URL. Every offering in a catalog should have a landing_url unless the format provides its own destination logic."
        ),
    ] = None
    name: Annotated[
        str,
        Field(
            description="Human-readable offering name (e.g., 'Winter Sale', 'Free Trial', 'Enterprise Platform')"
        ),
    ]
    offering_id: Annotated[
        str,
        Field(
            description='Unique identifier for this offering. Used by hosts to reference specific offerings in si_get_offering calls.'
        ),
    ]
    tagline: Annotated[
        str | None, Field(description='Short promotional tagline for the offering')
    ] = None
    valid_from: Annotated[
        AwareDatetime | None,
        Field(
            description='When the offering becomes available. If not specified, offering is immediately available.'
        ),
    ] = None
    valid_to: Annotated[
        AwareDatetime | None,
        Field(
            description='When the offering expires. If not specified, offering has no expiration.'
        ),
    ] = None
