"""
genesis_types.uco_schema — Pydantic models for Universal Cognition Objects.

PURPOSE:
    Canonical Python type definitions for UCOs, shared across:
    - genesis-core (creates and manages UCOs)
    - Any future Python microservices

    The TypeScript equivalent lives in uco_schema.ts (Zod schemas).
    Both MUST stay in sync. When modifying either, update the other.

UCO (Universal Cognition Object):
    The fundamental unit of work in Genesis OS. Every task, call, lead,
    conversation, and automation run is a UCO.

    See full architecture in:
    /mnt/e/genesis-system/genesis-os/apps/genesis-core/src/cognitive/uco_manager.py

TODO:
    - Implement UCOBase Pydantic model with all fields
    - Implement UCOCreate (input schema, no ID)
    - Implement UCOUpdate (partial update schema)
    - Implement UCOResponse (output schema, no internal fields)
    - Add field validators (e.g. max_cost_usd must be > 0)
    - Add UCOType and UCOStatus enums (should match uco_manager.py enums)
    - Write tests for serialization/deserialization round-trip
    - Verify JSON schema output matches uco_schema.ts Zod shape
"""

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any

# TODO: from pydantic import BaseModel, Field, field_validator, model_validator


# ---------------------------------------------------------------------------
# Enums (mirrors UCOType and UCOStatus in uco_manager.py)
# ---------------------------------------------------------------------------

class UCOType(str, Enum):
    """All valid UCO types in Genesis OS."""
    VOICE_CALL = "voice_call"
    LEAD_QUALIFICATION = "lead_qualification"
    CONTENT_GENERATION = "content_generation"
    WEBHOOK_PROCESSING = "webhook_processing"
    RLM_INGESTION = "rlm_ingestion"
    DEMO_SESSION = "demo_session"
    BILLING_EVENT = "billing_event"
    REPORT_GENERATION = "report_generation"


class UCOStatus(str, Enum):
    """All valid UCO lifecycle states."""
    PENDING = "pending"
    ACTIVE = "active"
    SUSPENDED = "suspended"
    COMPLETE = "complete"
    FAILED = "failed"
    CANCELLED = "cancelled"
    ARCHIVED = "archived"


# ---------------------------------------------------------------------------
# TODO: Pydantic models
# ---------------------------------------------------------------------------

# class UCOBase(BaseModel):
#     """Base UCO model with all shared fields."""
#
#     model_config = ConfigDict(
#         str_strip_whitespace=True,
#         validate_assignment=True,
#         populate_by_name=True,
#     )
#
#     uco_type: UCOType
#     status: UCOStatus
#     creator_id: str = Field(..., min_length=1, max_length=128)
#     location_id: str | None = Field(None, max_length=128)
#     objective: str = Field(..., min_length=1, max_length=4096)
#     success_criteria: list[str] = Field(default_factory=list)
#     context: dict[str, Any] = Field(default_factory=dict)
#
#     # Budget
#     max_cost_usd: float = Field(default=0.10, gt=0.0, le=100.0)
#     elapsed_cost_usd: float = Field(default=0.0, ge=0.0)
#     max_duration_ms: int = Field(default=60_000, gt=0)
#     elapsed_ms: float = Field(default=0.0, ge=0.0)
#
#     # Output
#     result: dict[str, Any] | None = None
#     error: str | None = Field(None, max_length=4096)
#     artifacts: list[str] = Field(default_factory=list)


# class UCOCreate(BaseModel):
#     """Schema for creating a new UCO (no ID, status defaults to PENDING)."""
#     uco_type: UCOType
#     objective: str = Field(..., min_length=1, max_length=4096)
#     context: dict[str, Any] = Field(default_factory=dict)
#     creator_id: str = Field(default="genesis-core")
#     location_id: str | None = None
#     success_criteria: list[str] = Field(default_factory=list)
#     max_cost_usd: float = Field(default=0.10, gt=0.0)
#     max_duration_ms: int = Field(default=60_000, gt=0)


# class UCOResponse(BaseModel):
#     """Schema for API responses — includes ID + timestamps, excludes internals."""
#     uco_id: str
#     uco_type: UCOType
#     status: UCOStatus
#     objective: str
#     creator_id: str
#     location_id: str | None
#     result: dict[str, Any] | None
#     error: str | None
#     created_at: str
#     activated_at: str | None
#     completed_at: str | None
