# generated by datamodel-codegen:
#   filename:  core/requirements/catalog_field_binding.json
#   timestamp: 2026-02-27T02:10:10+00:00

from __future__ import annotations

from typing import Annotated, Literal

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

from .. import ext as ext_1


class AssetPoolBinding(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    asset_group_id: Annotated[
        str,
        Field(
            description="The asset_group_id on the catalog item's assets array to pull from (e.g., 'images_landscape', 'images_vertical', 'logo')."
        ),
    ]
    asset_id: Annotated[
        str,
        Field(
            description="The asset_id from the format's assets array. Identifies which individual template slot this binding applies to."
        ),
    ]
    ext: ext_1.ExtensionObject | None = None
    kind: Literal['asset_pool']


class ScalarBinding(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    asset_id: Annotated[
        str,
        Field(
            description="The asset_id from the format's assets array. Identifies which individual template slot this binding applies to."
        ),
    ]
    catalog_field: Annotated[
        str,
        Field(
            description="Dot-notation path to the field on the catalog item (e.g., 'name', 'price.amount', 'location.city')."
        ),
    ]
    ext: ext_1.ExtensionObject | None = None
    kind: Literal['scalar']


class CatalogFieldBinding1(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    catalog_item: Annotated[
        Literal[True],
        Field(
            description="Each repetition of the format's repeatable_group maps to one item from the catalog."
        ),
    ]
    ext: ext_1.ExtensionObject | None = None
    format_group_id: Annotated[
        str,
        Field(description="The asset_group_id of a repeatable_group in the format's assets array."),
    ]
    kind: Literal['catalog_group']
    per_item_bindings: Annotated[
        list[ScalarBinding | AssetPoolBinding] | None,
        Field(
            description='Scalar and asset pool bindings that apply within each repetition of the group. Nested catalog_group bindings are not permitted.',
            min_length=1,
        ),
    ] = None


class CatalogFieldBinding(RootModel[ScalarBinding | AssetPoolBinding | CatalogFieldBinding1]):
    root: Annotated[
        ScalarBinding | AssetPoolBinding | CatalogFieldBinding1,
        Field(
            description="Maps a format template slot to a catalog item field or typed asset pool. The 'kind' field identifies the binding variant. All bindings are optional — agents can still infer mappings without them.",
            examples=[
                {
                    'data': {'asset_id': 'headline', 'catalog_field': 'name', 'kind': 'scalar'},
                    'description': 'Scalar binding — hotel name to headline slot',
                },
                {
                    'data': {
                        'asset_id': 'price_badge',
                        'catalog_field': 'price.amount',
                        'kind': 'scalar',
                    },
                    'description': 'Scalar binding — nested field (nightly rate)',
                },
                {
                    'data': {
                        'asset_group_id': 'images_landscape',
                        'asset_id': 'hero_image',
                        'kind': 'asset_pool',
                    },
                    'description': 'Asset pool binding — hero image from landscape pool',
                },
                {
                    'data': {
                        'asset_group_id': 'images_vertical',
                        'asset_id': 'snap_background',
                        'kind': 'asset_pool',
                    },
                    'description': 'Asset pool binding — Snap vertical background from vertical pool',
                },
                {
                    'data': {
                        'catalog_item': True,
                        'format_group_id': 'slide',
                        'kind': 'catalog_group',
                        'per_item_bindings': [
                            {'asset_id': 'title', 'catalog_field': 'name', 'kind': 'scalar'},
                            {
                                'asset_id': 'price',
                                'catalog_field': 'price.amount',
                                'kind': 'scalar',
                            },
                            {
                                'asset_group_id': 'images_landscape',
                                'asset_id': 'image',
                                'kind': 'asset_pool',
                            },
                        ],
                    },
                    'description': 'Catalog group binding — carousel where each slide is one hotel',
                },
            ],
            title='Catalog Field Binding',
        ),
    ]
