package com.ai.da.controller;

import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.entity.CloudTask;
import com.ai.da.mapper.primary.entity.CollectionSort;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*;
import com.ai.da.service.DesignService;
import com.ai.da.service.UserLikeGroupService;
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.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;


@Api(tags = "design模块")
@Slf4j
@RestController
@RequestMapping("/api/design")
public class DesignController {
    @Resource
    private DesignService designService;
    @Resource
    private UserLikeGroupService userLikeGroupService;

    @ApiOperation(value = "设计 Conllection")
    @PostMapping("/designCollection")
    @CrossOrigin
    public Response<String> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
        return Response.success(designService.designCollection(designDTO));
    }

    @ApiOperation(value = "design进度条")
    @GetMapping("/designProcess")
    public Response<Integer> designProcess(@RequestParam("processId") String processId) {
        return Response.success(designService.designProcess(processId));
    }

    @ApiOperation(value = "重新设计 Collection")
    @PostMapping("/reDesignCollection")
    public Response<String> reDesignCollection(@Valid @RequestBody ReDesignCollectionDTO reDesignDTO) {
        return Response.success(designService.reDesignCollection(reDesignDTO));
    }

    @ApiOperation(value = "designItem list,刷新用")
    @GetMapping("/designItemList")
    public Response<DesignCollectionVO> designItemList(@ApiParam("designId") @RequestParam("designId") Long designId) {
        return Response.success(designService.designItemList(designId));
    }

    @ApiOperation(value = "统计design进度")
    @PostMapping("/countDesignProcess")
    public Response<BigDecimal> countDesignProcess() {
        return Response.success(designService.countDesignProcess());
    }

    @ApiOperation(value = "Design Like")
    @PostMapping("/like")
    public Response<DesignLikeVO> like(@Valid @RequestBody DesignLikeDTO designLikeDTO) {
        return Response.success(designService.like(designLikeDTO));
    }

    @ApiOperation(value = "Design Dislike")
    @PostMapping("/dislike")
    public Response<Boolean> dislike(@Valid @RequestBody DisDesignLikeDTO disDesignLikeDTO) {
        return Response.success(designService.dislike(disDesignLikeDTO));
    }

    @ApiOperation(value = "Design sort")
    @PostMapping("/sort")
    public Response<Boolean> sort(@Valid @RequestBody CollectionSortDTO userLikeSortDTO) {
        return Response.success(designService.sort(userLikeSortDTO));
    }

    @ApiOperation(value = "sketchBoard upload generate design前裁剪")
    @PostMapping("/sketchBoardsBoundingBox")
    public Response<List<CollectionSketchVO>> sketchesBoundingBox(@Valid @RequestBody ReDesignCollectionDTO reDesignCollectionDTO) {
        return Response.success(designService.sketchesBoundingBox(reDesignCollectionDTO));
    }

    @ApiOperation(value = "通过designItemId获取模特图")
    @PostMapping("/getModel")
    public Response<List<String>> getModel(@RequestBody List<Long> designItemIdList){
        return Response.success(designService.getModel(designItemIdList));
    }

    @ApiOperation(value = "获取design结果")
    @GetMapping("/getDesignResult")
    public Response<DesignCollectionVO> getDesignResult(@RequestParam("requestId") String requestId, @RequestParam("objectSignList") List<String> objectSignList){
        return Response.success(designService.getDesignResult(requestId, objectSignList));
    }

    @ApiOperation(value = "云生成")
    @PostMapping("/designCloud")
    public Response<String> designCloud(@Valid @RequestBody CloudTaskDTO cloudTaskDTO) {
        return Response.success(designService.designCloud(cloudTaskDTO));
    }

    @ApiOperation(value = "云生成修改任务名")
    @PostMapping("/cloudTaskNameUpdate")
    public Response<Boolean> cloudTaskNameUpdate(@Valid @RequestBody CloudTaskDTO cloudTaskDTO) {
        return Response.success(designService.cloudTaskNameUpdate(cloudTaskDTO));
    }

    @ApiOperation(value = "云生成删除任务")
    @PostMapping("/cloudTaskDelete")
    public Response<Boolean> cloudTaskDelete(@Valid @RequestBody CloudTaskDTO cloudTaskDTO) {
        return Response.success(designService.cloudTaskDelete(cloudTaskDTO));
    }

    @ApiOperation(value = "云生成page")
    @PostMapping("/cloudPage")
    public Response<PageBaseResponse<CloudTaskVO>> cloudPage(@Valid @RequestBody CloudPageDTO cloudPageDTO) {
        return Response.success(PageBaseResponse.success(designService.cloudPage(cloudPageDTO)));
    }

    @ApiOperation(value = "获取design云生成结果")
    @PostMapping("/getDesignCloudResult")
    public Response<CloudTaskResultVO> getDesignCloudResult(@Valid @RequestBody DesignCloudResultQuery designCloudResultQuery) {
        return Response.success(designService.getDesignCloudResult(designCloudResultQuery));
    }
}
