# generated by datamodel-codegen:
#   filename:  core/delivery_metrics.json
#   timestamp: 2026-01-08T19:25:24+00:00

from __future__ import annotations

from typing import Annotated

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


class VenueBreakdownItem(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    impressions: Annotated[int, Field(description='Impressions delivered at this venue', ge=0)]
    loop_plays: Annotated[int | None, Field(description='Loop plays at this venue', ge=0)] = None
    screens_used: Annotated[
        int | None, Field(description='Number of screens used at this venue', ge=0)
    ] = None
    venue_id: Annotated[str, Field(description='Venue identifier')]
    venue_name: Annotated[str | None, Field(description='Human-readable venue name')] = None
    venue_type: Annotated[
        str | None,
        Field(description="Venue type (e.g., 'airport', 'transit', 'retail', 'billboard')"),
    ] = None


class DoohMetrics(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    calculation_notes: Annotated[
        str | None, Field(description='Explanation of how DOOH impressions were calculated')
    ] = None
    loop_plays: Annotated[
        int | None, Field(description='Number of times ad played in rotation', ge=0)
    ] = None
    screen_time_seconds: Annotated[
        int | None, Field(description='Total display time in seconds', ge=0)
    ] = None
    screens_used: Annotated[
        int | None, Field(description='Number of unique screens displaying the ad', ge=0)
    ] = None
    sov_achieved: Annotated[
        float | None,
        Field(description='Actual share of voice delivered (0.0 to 1.0)', ge=0.0, le=1.0),
    ] = None
    venue_breakdown: Annotated[
        list[VenueBreakdownItem] | None, Field(description='Per-venue performance breakdown')
    ] = None


class QuartileData(AdCPBaseModel):
    q1_views: Annotated[float | None, Field(description='25% completion views', ge=0.0)] = None
    q2_views: Annotated[float | None, Field(description='50% completion views', ge=0.0)] = None
    q3_views: Annotated[float | None, Field(description='75% completion views', ge=0.0)] = None
    q4_views: Annotated[float | None, Field(description='100% completion views', ge=0.0)] = None


class DeliveryMetrics(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    clicks: Annotated[float | None, Field(description='Total clicks', ge=0.0)] = None
    completed_views: Annotated[
        float | None, Field(description='100% completions (for CPCV)', ge=0.0)
    ] = None
    completion_rate: Annotated[
        float | None,
        Field(description='Completion rate (completed_views/impressions)', ge=0.0, le=1.0),
    ] = None
    conversions: Annotated[
        float | None,
        Field(description='Conversions (reserved for future CPA pricing support)', ge=0.0),
    ] = None
    ctr: Annotated[
        float | None, Field(description='Click-through rate (clicks/impressions)', ge=0.0, le=1.0)
    ] = None
    dooh_metrics: Annotated[
        DoohMetrics | None,
        Field(description='DOOH-specific metrics (only included for DOOH campaigns)'),
    ] = None
    frequency: Annotated[
        float | None,
        Field(
            description='Average frequency per individual (typically measured over campaign duration, but can vary by measurement provider)',
            ge=0.0,
        ),
    ] = None
    grps: Annotated[
        float | None, Field(description='Gross Rating Points delivered (for CPP)', ge=0.0)
    ] = None
    impressions: Annotated[float | None, Field(description='Impressions delivered', ge=0.0)] = None
    leads: Annotated[
        float | None,
        Field(description='Leads generated (reserved for future CPL pricing support)', ge=0.0),
    ] = None
    quartile_data: Annotated[
        QuartileData | None, Field(description='Video quartile completion data')
    ] = None
    reach: Annotated[
        float | None,
        Field(
            description='Unique reach - units depend on measurement provider (e.g., individuals, households, devices, cookies). See delivery_measurement.provider for methodology.',
            ge=0.0,
        ),
    ] = None
    spend: Annotated[float | None, Field(description='Amount spent', ge=0.0)] = None
    views: Annotated[float | None, Field(description='Views at threshold (for CPV)', ge=0.0)] = None
