# generated by datamodel-codegen:
#   filename:  core/targeting.json
#   timestamp: 2026-01-25T21:17:54+00:00

from __future__ import annotations

from typing import Annotated

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

from ..enums import metro_system, postal_system
from . import frequency_cap as frequency_cap_1


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


class GeoMetro(AdCPBaseModel):
    model_config = ConfigDict(
        extra='forbid',
    )
    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 (e.g., ['501', '602'] for Nielsen DMAs)",
            min_length=1,
        ),
    ]


class GeoPostalArea(AdCPBaseModel):
    model_config = ConfigDict(
        extra='forbid',
    )
    system: Annotated[
        postal_system.PostalCodeSystem,
        Field(
            description="Postal code system (e.g., 'us_zip', 'gb_outward'). System name encodes country and precision."
        ),
    ]
    values: Annotated[
        list[str],
        Field(
            description="Postal codes within the system (e.g., ['10001', '10002'] for us_zip)",
            min_length=1,
        ),
    ]


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


class TargetingOverlay(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    axe_exclude_segment: Annotated[
        str | None, Field(description='AXE segment ID to exclude from targeting')
    ] = None
    axe_include_segment: Annotated[
        str | None, Field(description='AXE segment ID to include for targeting')
    ] = None
    frequency_cap: frequency_cap_1.FrequencyCap | None = None
    geo_countries: Annotated[
        list[GeoCountry] | None,
        Field(
            description="Restrict delivery to specific countries. ISO 3166-1 alpha-2 codes (e.g., 'US', 'GB', 'DE')."
        ),
    ] = None
    geo_metros: Annotated[
        list[GeoMetro] | None,
        Field(
            description='Restrict delivery to specific metro areas. Each entry specifies the classification system and target values. Seller must declare supported systems in get_adcp_capabilities.'
        ),
    ] = None
    geo_postal_areas: Annotated[
        list[GeoPostalArea] | None,
        Field(
            description='Restrict delivery to specific postal areas. Each entry specifies the postal system and target values. Seller must declare supported systems in get_adcp_capabilities.'
        ),
    ] = None
    geo_regions: Annotated[
        list[GeoRegion] | None,
        Field(
            description="Restrict delivery to specific regions/states. ISO 3166-2 subdivision codes (e.g., 'US-CA', 'GB-SCT')."
        ),
    ] = None
