import json
import logging

from fastapi import APIRouter, HTTPException

from app.schemas.mannequin_edit import MannequinModel
from app.schemas.response_template import ResponseModel
from app.service.mannequins_edit.service import MannequinEditService

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


@router.post("/mannequins_edit")
def mannequins_edit(request_data: MannequinModel):
    """
        模特腿长调整
        创建一个具有以下参数的请求体:
        - **mannequins**: mannequins url等信息
        - **resize_pixel**: 拉伸像素量
        - **bucket_name**: bucket name
        - **mannequin_name**: 模特名称
        - **top**: 拉伸y轴点位
        - **bottom**: 拉伸y轴点位


        示例参数：
        - **{
          "mannequins": "aida-sys-image/models/male/dc36ce58-46c3-4b6f-8787-5ca7d6fc26e6.png",
          "resize_pixel": -50,
          "bucket_name": "test",
          "mannequin_name": "mannequin_name",
          "top" : 270,
          "bottom" : 432
        }**
    """
    try:
        logger.info(f"mannequins_edit request item is : @@@@@@:{json.dumps(request_data.dict())}")
        service = MannequinEditService(request_data)
        data = service()
        logger.info(f"mannequins_edit response @@@@@@:{json.dumps(data)}")
    except Exception as e:
        logger.warning(f"mannequins_edit Run Exception @@@@@@:{e}")
        raise HTTPException(status_code=404, detail=str(e))
    return ResponseModel(data=data)
