import json
import logging

from fastapi import APIRouter, HTTPException

from app.schemas.image2sketch import Image2SketchModel
from app.schemas.response_template import ResponseModel
from app.service.lineart.service import LineArtService

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


@router.post("/image2sketch")
def image2sketch(request_item: Image2SketchModel):
    """
        创建一个具有以下参数的请求体:
        - **image_url**: 提取图片url
        - **default_style**:  原始、 1、2、3、4、5
        - **sketch_bucket**: sketch保存的bucket
        - **sketch_name**: sketch保存的object name

        示例参数：
        {
          "image_url": "test/image2sketch/real_Dress_3200fecdc83d0c556c2bd96aedbd7fbf.jpg_Img.jpg",
          "default_style": 0,
          "sketch_bucket": "test",
          "sketch_name": "image2sketch/area_fill_img.png"
        }
    """
    try:
        logger.info(f"image2sketch request item is : @@@@@@:{json.dumps(request_item.dict())}")
        service = LineArtService(request_item)
        result_url = service.get_result()
    except Exception as e:
        logger.warning(f"image2sketch Run Exception @@@@@@:{e}")
        raise HTTPException(status_code=404, detail=str(e))
    return ResponseModel(data=result_url)
