"""Pydantic models for Influ2 API request/response validation."""

from __future__ import annotations

from pydantic import BaseModel, Field


# --- Target Models ---


class TargetInput(BaseModel):
    """A target person to add/update/remove in a cohort."""

    external_id: str = Field(..., min_length=1, max_length=256)
    target_id: str | None = None
    first_name: str | None = None
    last_name: str | None = None
    email: str | None = None
    title: str | None = None
    company_name: str | None = None
    company_website: str | None = None
    linkedin: str | None = None


# --- Content Models ---


class SocialMetadata(BaseModel):
    """Social ad metadata (Facebook/LinkedIn)."""

    title: str | None = None
    description: str | None = None
    text: str | None = None
    facebook_page_url: str | None = None
    linkedin_page_url: str | None = None


class NativeMetadata(BaseModel):
    """Native ad metadata."""

    title: str | None = None
    description: str | None = None


class CarouselItem(BaseModel):
    """A single carousel card."""

    title: str | None = None
    description: str | None = None
    link: str | None = None
    images: list[str] = Field(default_factory=list)


class ContentInput(BaseModel):
    """Content/creative configuration for creating an ad."""

    external_id: str = Field(..., min_length=1, max_length=255)
    name: str = Field(..., min_length=1, max_length=255)
    type: str = Field(..., pattern="^(video|images)$")
    link: str | None = None
    social: SocialMetadata | None = None
    native: NativeMetadata | None = None
    carousel_items: list[CarouselItem] | None = None
    images: list[str] | None = None
    videos: list[str] | None = None


# --- Cohort Bundle Models ---


class CohortInput(BaseModel):
    """Cohort configuration for bundle creation."""

    name: str = Field(..., min_length=1)


class CohortBundleInput(BaseModel):
    """Full cohort bundle: cohort + targets + contents."""

    cohort: CohortInput
    targets: list[TargetInput] = Field(..., min_length=1, max_length=10000)
    contents: list[ContentInput] = Field(..., min_length=1, max_length=50)


# --- Job Models ---


class JobStatus(BaseModel):
    """Status of an async operation."""

    id: str
    status: str
    action: str | None = None
    created_at: str | None = None
    updated_at: str | None = None
