from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field


class PipelineCreate(BaseModel):
    name: str = Field(..., min_length=1, max_length=120)
    is_default: bool = False


class PipelineUpdate(BaseModel):
    name: str | None = Field(None, min_length=1, max_length=120)
    is_default: bool | None = None


class PipelineResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    name: str
    is_default: bool
    tenant_id: int
    company_id: int
    created_at: datetime
    updated_at: datetime


class StageCreate(BaseModel):
    pipeline_id: int
    name: str = Field(..., min_length=1, max_length=120)
    position: int = Field(0, ge=0)
    probability: int = Field(0, ge=0, le=100)
    is_won: bool = False
    is_lost: bool = False


class StageUpdate(BaseModel):
    name: str | None = Field(None, min_length=1, max_length=120)
    position: int | None = Field(None, ge=0)
    probability: int | None = Field(None, ge=0, le=100)
    is_won: bool | None = None
    is_lost: bool | None = None


class StageResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    pipeline_id: int
    name: str
    position: int
    probability: int
    is_won: bool
    is_lost: bool
    tenant_id: int
    company_id: int
    created_at: datetime
    updated_at: datetime
