# generated by datamodel-codegen:
#   filename:  core/audience_member.json
#   timestamp: 2026-02-27T02:10:10+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 uid_type
from . import ext as ext_1


class Uid(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    type: Annotated[uid_type.UidType, Field(description='Universal ID type')]
    value: Annotated[str, Field(description='Universal ID value')]


class AudienceMember1(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    ext: ext_1.ExtensionObject | None = None
    external_id: Annotated[
        str,
        Field(
            description="Buyer-assigned stable identifier for this audience member (e.g. CRM record ID, loyalty ID). Used for deduplication, removal, and cross-referencing with buyer systems. Adapters for CDPs that don't natively assign IDs can derive one (e.g. hash of the member's identifiers)."
        ),
    ]
    hashed_email: Annotated[
        str,
        Field(
            description='SHA-256 hash of lowercase, trimmed email address.',
            pattern='^[a-f0-9]{64}$',
        ),
    ]
    hashed_phone: Annotated[
        str | None,
        Field(
            description='SHA-256 hash of E.164-formatted phone number (e.g. +12065551234).',
            pattern='^[a-f0-9]{64}$',
        ),
    ] = None
    uids: Annotated[
        list[Uid] | None,
        Field(
            description='Universal ID values (MAIDs, RampID, UID2, etc.) for user matching.',
            min_length=1,
        ),
    ] = None


class AudienceMember2(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    ext: ext_1.ExtensionObject | None = None
    external_id: Annotated[
        str,
        Field(
            description="Buyer-assigned stable identifier for this audience member (e.g. CRM record ID, loyalty ID). Used for deduplication, removal, and cross-referencing with buyer systems. Adapters for CDPs that don't natively assign IDs can derive one (e.g. hash of the member's identifiers)."
        ),
    ]
    hashed_email: Annotated[
        str | None,
        Field(
            description='SHA-256 hash of lowercase, trimmed email address.',
            pattern='^[a-f0-9]{64}$',
        ),
    ] = None
    hashed_phone: Annotated[
        str,
        Field(
            description='SHA-256 hash of E.164-formatted phone number (e.g. +12065551234).',
            pattern='^[a-f0-9]{64}$',
        ),
    ]
    uids: Annotated[
        list[Uid] | None,
        Field(
            description='Universal ID values (MAIDs, RampID, UID2, etc.) for user matching.',
            min_length=1,
        ),
    ] = None


class AudienceMember3(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    ext: ext_1.ExtensionObject | None = None
    external_id: Annotated[
        str,
        Field(
            description="Buyer-assigned stable identifier for this audience member (e.g. CRM record ID, loyalty ID). Used for deduplication, removal, and cross-referencing with buyer systems. Adapters for CDPs that don't natively assign IDs can derive one (e.g. hash of the member's identifiers)."
        ),
    ]
    hashed_email: Annotated[
        str | None,
        Field(
            description='SHA-256 hash of lowercase, trimmed email address.',
            pattern='^[a-f0-9]{64}$',
        ),
    ] = None
    hashed_phone: Annotated[
        str | None,
        Field(
            description='SHA-256 hash of E.164-formatted phone number (e.g. +12065551234).',
            pattern='^[a-f0-9]{64}$',
        ),
    ] = None
    uids: Annotated[
        list[Uid],
        Field(
            description='Universal ID values (MAIDs, RampID, UID2, etc.) for user matching.',
            min_length=1,
        ),
    ]


class AudienceMember(RootModel[AudienceMember1 | AudienceMember2 | AudienceMember3]):
    root: Annotated[
        AudienceMember1 | AudienceMember2 | AudienceMember3,
        Field(
            description='A CRM audience member identified by a buyer-assigned external_id and at least one matchable identifier. All identifiers must be normalized before hashing: emails to lowercase+trim, phone numbers to E.164 format (e.g. +12065551234). Providing multiple identifiers for the same person improves match rates. Composite identifiers (e.g. hashed first name + last name + zip for Google Customer Match) are not yet standardized — use the ext field for platform-specific extensions.',
            title='Audience Member',
        ),
    ]
