from __future__ import annotations

from enum import StrEnum
from typing import Literal

from pydantic import BaseModel, Field


class PostAngle(StrEnum):
    CONTRARIAN = "contrarian"
    FIELD_NOTE = "field_note"
    DEMYSTIFICATION = "demystification"
    IDENTITY_VALIDATION = "identity_validation"
    PROVOCATEUR = "provocateur"
    SYNTHESIZER = "synthesizer"
    CURIOUS_CAT = "curious_cat"


class RefineIntensity(StrEnum):
    LIGHT = "light"
    MEDIUM = "medium"
    HEAVY = "heavy"


class StylePreset(StrEnum):
    TYPOGRAPHIC_MINIMAL = "typographic_minimal"
    GRADIENT_TEXT = "gradient_text"
    DARK_MODE = "dark_mode"
    ACCENT_BAR = "accent_bar"
    ABSTRACT_SHAPES = "abstract_shapes"


# ── Request models ─────────────────────────────────────────────


class AnalyzeRequest(BaseModel):
    text: str
    context: str | None = None


class ReshapeRequest(BaseModel):
    text: str
    angles: list[PostAngle]
    pre_edit: bool | None = Field(None, alias="preEdit")
    instructions: str | None = None
    save_drafts: bool | None = Field(None, alias="saveDrafts")

    model_config = {"populate_by_name": True}


class RefineRequest(BaseModel):
    text: str
    intensity: RefineIntensity | None = None
    instructions: str | None = None
    post_type: str | None = Field(None, alias="postType")
    save_draft: bool | None = Field(None, alias="saveDraft")

    model_config = {"populate_by_name": True}


class SplitRequest(BaseModel):
    text: str
    max_posts: int | None = Field(None, alias="maxPosts", ge=2, le=10)
    instructions: str | None = None
    save_drafts: bool | None = Field(None, alias="saveDrafts")

    model_config = {"populate_by_name": True}


class DraftRequest(BaseModel):
    full_text: str = Field(alias="fullText")
    hook: str | None = None
    post_type: str | None = Field(None, alias="postType")
    approved: bool | None = None
    auto_publish: bool | None = Field(None, alias="autoPublish")
    scheduled_at: str | None = Field(None, alias="scheduledAt")

    model_config = {"populate_by_name": True}


class CarouselSlide(BaseModel):
    headline_text: str = Field(alias="headlineText")
    caption: str | None = None

    model_config = {"populate_by_name": True}


class BundleRequest(BaseModel):
    full_text: str = Field(alias="fullText")
    hook: str | None = None
    post_type: str | None = Field(None, alias="postType")
    approved: bool | None = None
    auto_publish: bool | None = Field(None, alias="autoPublish")
    scheduled_at: str | None = Field(None, alias="scheduledAt")
    image_headline_text: str | None = Field(None, alias="imageHeadlineText")
    image_style_preset: StylePreset | None = Field(None, alias="imageStylePreset")
    carousel_slides: list[CarouselSlide] | None = Field(None, alias="carouselSlides")

    model_config = {"populate_by_name": True}


class PostsListParams(BaseModel):
    approved: bool | None = None
    scheduled: bool | None = None
    published: bool | None = None
    type: str | None = None
    limit: int | None = None
    offset: int | None = None


class PostUpdateRequest(BaseModel):
    full_text: str | None = Field(None, alias="fullText")
    hook: str | None = None
    auto_publish: bool | None = Field(None, alias="autoPublish")

    model_config = {"populate_by_name": True}


class ScheduleRequest(BaseModel):
    scheduled_at: str | None = Field(alias="scheduledAt")
    auto_publish: bool | None = Field(None, alias="autoPublish")

    model_config = {"populate_by_name": True}


class ImageRequest(BaseModel):
    headline_text: str = Field(alias="headlineText")
    style_preset: StylePreset | None = Field(None, alias="stylePreset")

    model_config = {"populate_by_name": True}


class CarouselRequest(BaseModel):
    slides: list[CarouselSlide]
    style_preset: StylePreset | None = Field(None, alias="stylePreset")

    model_config = {"populate_by_name": True}
