"""
Telemetry schemas (4A.2).
"""

from __future__ import annotations

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


class TelemetryKpiWindow(BaseModel):
    days: int = Field(ge=1, le=365)
    start: datetime
    end: datetime


class DealFunnelKpis(BaseModel):
    listing_views: int = 0
    inquiries_created: int = 0
    seller_replied_inquiries: int = 0
    inquiry_reply_rate: float = 0.0

    listings_with_inquiries: int = 0
    listings_sold: int = 0
    inquiry_to_sold_listing_rate: float = 0.0

    median_reply_seconds: Optional[float] = None
    median_time_to_sold_seconds: Optional[float] = None


class YieldFunnelKpis(BaseModel):
    connected_domains: int = 0
    clicks: int = 0
    conversions: int = 0
    conversion_rate: float = 0.0

    payouts_paid: int = 0
    payouts_paid_amount_total: float = 0.0


class TelemetryKpisResponse(BaseModel):
    window: TelemetryKpiWindow
    deal: DealFunnelKpis
    yield_: YieldFunnelKpis = Field(alias="yield")

