#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Isometquick API数据模型
定义请求和响应的数据结构
"""

from pydantic import BaseModel, Field
from typing import Optional, Literal
from datetime import datetime


class RoomDimensions(BaseModel):
    """房间尺寸参数"""
    length: float = Field(default=4.0, ge=1.0, le=20.0, description="房间长度(X轴)")
    width: float = Field(default=4.0, ge=1.0, le=20.0, description="房间宽度(Y轴)")
    height: float = Field(default=3.0, ge=1.0, le=10.0, description="房间高度(Z轴)")
    prop_type: int = Field(default=0, ge=0, le=3,
                           description="道具类型: 0=无, 1=窗, 2=拱门, 3=门")


class CameraSettings(BaseModel):
    """摄像机设置参数"""
    height: float = Field(default=1.3, ge=0.5, le=5.0,
                          description="摄像机垂直高度(米)")
    view_type: Literal[1, 2] = Field(
        default=2, description="视图类型: 1=正视图, 2=侧视图")
    rotation_angle: float = Field(
        default=45.0, ge=0.0, le=360.0, description="摄像机旋转角度(度)")


class RenderSettings(BaseModel):
    """渲染设置参数"""
    resolution_x: int = Field(default=1080, ge=256,
                              le=4096, description="渲染宽度")
    resolution_y: int = Field(default=2400, ge=256,
                              le=4096, description="渲染高度")
    engine: Literal["workbench", "eevee", "cycles"] = Field(
        default="workbench", description="渲染引擎")


class RenderRequest(BaseModel):
    """渲染请求模型"""
    room: RoomDimensions = Field(
        default_factory=RoomDimensions, description="房间尺寸参数")
    camera: CameraSettings = Field(
        default_factory=CameraSettings, description="摄像机设置")
    render: RenderSettings = Field(
        default_factory=RenderSettings, description="渲染设置")

    class Config:
        json_schema_extra = {
            "example": {
                "room": {
                    "length": 4.0,
                    "width": 4.0,
                    "height": 3.0,
                    "prop_type": 0
                },
                "camera": {
                    "height": 1.3,
                    "view_type": 2,
                    "rotation_angle": 45.0
                },
                "render": {
                    "resolution_x": 1080,
                    "resolution_y": 2400,
                    "engine": "workbench"
                }
            }
        }


class RenderResponse(BaseModel):
    """渲染响应模型"""
    task_id: str = Field(description="任务唯一标识符")
    status: str = Field(description="任务状态")
    message: str = Field(description="响应消息")
    created_at: Optional[datetime] = Field(default=None, description="创建时间")


class RenderStatus(BaseModel):
    """渲染状态模型"""
    task_id: str = Field(description="任务唯一标识符")
    status: str = Field(
        description="任务状态: pending/processing/completed/failed")
    created_at: str = Field(description="创建时间")
    completed_at: Optional[str] = Field(default=None, description="完成时间")
    output_file: Optional[str] = Field(default=None, description="输出文件路径")
    image_base64: Optional[str] = Field(
        default=None, description="图片的base64编码")
    error: Optional[str] = Field(default=None, description="错误信息")


class ApiResponse(BaseModel):
    """通用API响应模型"""
    success: bool = Field(description="操作是否成功")
    message: str = Field(description="响应消息")
    data: Optional[dict] = Field(default=None, description="响应数据")
    timestamp: datetime = Field(
        default_factory=datetime.now, description="响应时间")
