package com.ai.da.controller;

import com.ai.da.common.response.Response;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*;
import com.ai.da.service.DesignItemService;
import com.ai.da.service.DesignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;


@Api(tags = "design Detail模块")
@Slf4j
@RestController
@RequestMapping("/api/design/detail")
public class DesignDetailController {
    @Resource
    private DesignService designService;
    @Resource
    private DesignItemService designItemService;

    @ApiOperation(value = "生成高级design图片")
    @PostMapping("/generateHighDesign")
    public Response<String> generateHighDesign(@Valid @RequestBody GenerateHighDesignDTO generateHighDesignDTO) {
        Response response = new Response();
        response.setData(designService.generateHighDesign(generateHighDesignDTO));
        return response;
    }

    @ApiOperation(value = "删除高级design图片")
    @PostMapping("/deleteHighDesign")
    public Response<Boolean> deleteHighDesign(@Valid @RequestBody GenerateHighDesignDTO generateHighDesignDTO) {
        Response response = new Response();
        response.setData(designService.deleteHighDesign(generateHighDesignDTO));
        return response;
    }

    @ApiOperation(value = "查询design详情")
    @GetMapping("/getDetail")
    public Response<DesignItemDetailVO> getDetail(@ApiParam("designItemId") @RequestParam("designItemId") Long designItemId,
                                                  @ApiParam("designPythonOutfitId") @RequestParam(value = "designPythonOutfitId", required = false) Long designPythonOutfitId) {
        return Response.success(designService.detail(designPythonOutfitId, designItemId));
    }

    @ApiOperation(value = "切换系统的element")
    @GetMapping("/getNextSysElement")
    public Response<GetNextSysElementVO> getNextSysElement(@ApiParam("要切换的系统element 类型") @RequestParam("type") String type,
                                                           @ApiParam("要切换的系统element id") @RequestParam("id") Long id,
                                                           @ApiParam("操作类型 PREV 上一步  NEXT 下一步") @RequestParam("operateType") String operateType) {
        return Response.success(designItemService.getNextSysElement(id, type, operateType));
    }

    @ApiOperation(value = "单个design")
    @PostMapping("/designSingle")
    public Response<DesignSingleVO> designSingle(@Valid @RequestBody DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) {
        return Response.success(designItemService.designSingleIncludeLayers(designSingleIncludeLayersDTO));
    }

    @ApiOperation(value = "print打点")
    @PostMapping("/printDot")
    public Response<String> printDot(@Valid @RequestBody DesignSingleDTO designSingleDTO) {
        Response<String> response = new Response();
        String url = designItemService.printDot(designSingleDTO);
        response.setData(url);
        return response;
    }

    @ApiOperation(value = "编辑图层大小和位置  废弃")
    @PostMapping("/editLayers")
    public Response<ComposeLayersVO> editPositionAndScale(@Valid @RequestBody EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException {
        return Response.success(designItemService.editLayersPositionAndScale(positionAndScaleVO));
    }

    @ApiOperation(value = "mask数据兼容")
    @GetMapping("/convertWithoutGradient")
    public Response<String> convertHistoryMaskWithoutGradient(){
        designItemService.convertHistoryMaskWithoutGradient();
        return Response.success("success");
    }

    @ApiOperation(value = "mask数据库路径更新")
    @GetMapping("/updateMaskUrl")
    public Response<String> updateMaskUrl(){
        designItemService.updateMaskUrl();
        return Response.success("success");
    }
}
