"""Professional error response models for API."""

from typing import Optional, Any, Dict
from pydantic import BaseModel, Field
from datetime import datetime


class ErrorDetail(BaseModel):
    """Detailed error information."""
    field: Optional[str] = Field(None, description="Field name that caused the error")
    message: str = Field(..., description="Error message")
    code: Optional[str] = Field(None, description="Error code")


class ErrorResponse(BaseModel):
    """Standardized error response model."""
    success: bool = Field(False, description="Request success status")
    error: ErrorDetail = Field(..., description="Error details")
    timestamp: str = Field(default_factory=lambda: datetime.utcnow().isoformat(), description="Error timestamp")
    path: Optional[str] = Field(None, description="Request path")
    request_id: Optional[str] = Field(None, description="Request ID for tracing")
    
    class Config:
        json_schema_extra = {
            "example": {
                "success": False,
                "error": {
                    "field": "pickup_location",
                    "message": "Pickup location is required",
                    "code": "VALIDATION_ERROR"
                },
                "timestamp": "2024-01-15T10:30:00.000Z",
                "path": "/api/v1/optimization/single-route",
                "request_id": "req-123456"
            }
        }


class SuccessResponse(BaseModel):
    """Standardized success response wrapper."""
    success: bool = Field(True, description="Request success status")
    data: Any = Field(..., description="Response data")
    timestamp: str = Field(default_factory=lambda: datetime.utcnow().isoformat(), description="Response timestamp")
    request_id: Optional[str] = Field(None, description="Request ID for tracing")

