import json
import logging

from fastapi import APIRouter, HTTPException

from app.schemas.pre_processing import DesignPreProcessingModel
from app.schemas.response_template import ResponseModel
from app.service.design_pre_processing.service import DesignPreprocessing

router = APIRouter()
logger = logging.getLogger()


@router.post("/design_pre_processing")
def design_pre_processing(request_data: DesignPreProcessingModel):
    """
        design 预处理 获取sketch的基本信息
        创建一个具有以下参数的请求体:
        - **sketches**: sketch url等信息

        示例参数：
        {
            "sketches": [
                {
                    "image_category": "dress",
                    "image_id": "107903",
                    "image_url": "aida-sys-image/images/female/dress/0628000000.jpg"
                }
            ]
        }
    """
    try:
        logger.info(f"design_pre_processing request item is : @@@@@@:{json.dumps(request_data.dict())}")
        server = DesignPreprocessing()
        data = server.pipeline(image_list=request_data.sketches)
        logger.info(f"design response @@@@@@:{json.dumps(data)}")
    except Exception as e:
        logger.warning(f"design Run Exception @@@@@@:{e}")
        raise HTTPException(status_code=404, detail=str(e))
    return ResponseModel(data=data)
