"""
Pydantic models for Bible-Companion API requests and responses.
"""

from typing import Optional, List
from datetime import datetime
from pydantic import BaseModel, Field


class ChatRequest(BaseModel):
    """Request model for /api/chat endpoint"""
    message: str = Field(..., description="User's question or request")
    conversation_id: Optional[str] = Field(
        None,
        description="Optional conversation ID for maintaining context across messages"
    )
    include_doctrinal_context: bool = Field(
        True,
        description="Whether to include doctrinal commentary in response"
    )

    class Config:
        example = {
            "message": "What does Scripture teach about redemption?",
            "conversation_id": "conv_2026-01-12T10:30:00",
            "include_doctrinal_context": True
        }


class ScriptureReference(BaseModel):
    """A single Scripture reference (e.g., "John 3:16")"""
    reference: str = Field(..., description="Scripture reference (e.g., 'John 3:16')")

    class Config:
        example = {"reference": "John 3:16"}


class ScriptureVerse(BaseModel):
    """A Scripture verse in a specific translation"""
    reference: str = Field(..., description="Scripture reference")
    text: str = Field(..., description="Verse text")
    translation: str = Field(..., description="Translation name (KJV, NIV, etc.)")

    class Config:
        example = {
            "reference": "John 3:16",
            "text": "For God so loved the world, that he gave his only begotten Son...",
            "translation": "KJV"
        }


class EnrichedVerse(BaseModel):
    """A Scripture reference enriched with all translations and doctrinal context"""
    reference: str = Field(..., description="Scripture reference")
    verses: List[ScriptureVerse] = Field(
        ...,
        description="Verse text in all available translations"
    )
    doctrinal_context: Optional[str] = Field(
        None,
        description="Doctrinal commentary on this Scripture from Oracle"
    )

    class Config:
        example = {
            "reference": "John 3:16",
            "verses": [
                {
                    "reference": "John 3:16",
                    "text": "For God so loved the world...",
                    "translation": "KJV"
                }
            ],
            "doctrinal_context": "This verse encapsulates the Gospel: God's redemptive love expressed through Christ's incarnation and atonement."
        }


class ChatResponse(BaseModel):
    """Response model for /api/chat endpoint"""
    conversation_id: str = Field(..., description="Conversation identifier")
    user_message: str = Field(..., description="User's original message")
    response: str = Field(..., description="AI's response")
    scripture_references: List[EnrichedVerse] = Field(
        default_factory=list,
        description="Scripture passages referenced in response, enriched with translations"
    )
    model: str = Field(..., description="Model identifier")
    timestamp: str = Field(..., description="Response timestamp (ISO 8601)")

    class Config:
        example = {
            "conversation_id": "conv_2026-01-12T10:30:00",
            "user_message": "What does Scripture teach about redemption?",
            "response": "Scripture teaches that redemption is God's redemptive action through Christ...",
            "scripture_references": [
                {
                    "reference": "John 3:16",
                    "verses": [...],
                    "doctrinal_context": "..."
                }
            ],
            "model": "Bible-Companion (LFM2.5)",
            "timestamp": "2026-01-12T10:30:45.123456"
        }


class HealthCheck(BaseModel):
    """Health check response"""
    status: str = Field(..., description="Service status")
    service: str = Field(..., description="Service name")
    inference_url: str = Field(..., description="Inference endpoint URL")
    model: str = Field(..., description="Model name")
