package com.ai.da.controller;

import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.entity.Style;
import com.ai.da.mapper.primary.entity.Workspace;
import com.ai.da.model.dto.ProjectDTO;
import com.ai.da.model.dto.WorkspaceDTO;
import com.ai.da.model.dto.WorkspaceSaveDTO;
import com.ai.da.model.enums.BizJson;
import com.ai.da.model.vo.ModelsVO;
import com.ai.da.model.vo.StyleVO;
import com.ai.da.model.vo.WorkspaceVO;
import com.ai.da.service.WorkspaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;

import javax.annotation.Resource;
import javax.validation.Valid;

import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.util.List;

/**
 * 控制器
 *
 * @author SHAHAIBO
 * @since 2023-08-01
 */
@RestController
@AllArgsConstructor
@NoArgsConstructor
@RequestMapping("/api/workspace")
@Api(value = "", tags = "工作空间")
public class WorkspaceController {

    @Resource
    private WorkspaceService workspaceService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入workspace")
    public Response<WorkspaceVO> detail(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
        WorkspaceVO detail = workspaceService.getByIdNew(id);
        return Response.success(detail);
    }

    /**
     * 分页
     */
    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入workspace")
    public Response<WorkspaceVO> list(@Valid @RequestBody WorkspaceDTO query) {
        WorkspaceVO response = workspaceService.getPage(query);
        return Response.success(response);
    }

    /**
     * 新增或编辑
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增或编辑", notes = "传入workspace")
    public Response saveOrUpdate(@Valid @RequestBody WorkspaceSaveDTO workspaceDTO) {
        return Response.success(workspaceService.saveOrUpdate(workspaceDTO));
    }


    /**
     * 删除
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "传入id")
    public Response<List<Long>> remove(@Valid @RequestBody List<Workspace> workspaceList) {
        return Response.success(workspaceService.delete(workspaceList));
    }

    @GetMapping("/enumValues")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "获取枚举类值")
    public Response<List<BizJson>> enumValues(@RequestParam("enumName") String enumName) {
        List<BizJson> bizJsonList = workspaceService.getEnumValues(enumName);
        return Response.success(bizJsonList);
    }

    @GetMapping("/getMannequins")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "获取模特")
    public Response<List<ModelsVO>> getMannequins(@RequestParam("sex") String sex, @RequestParam("style") String style, @RequestParam("ageGroup") String ageGroup) {
        List<ModelsVO> modelsVO = workspaceService.getMannequins(sex, style, ageGroup);
        return Response.success(modelsVO);
    }


    @PostMapping("system_file_copy")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "minio数据迁移")
    public Response<Boolean> systemFileCopy() {
        workspaceService.systemFileCopy();
        return Response.success(true);
    }

    @PostMapping("moveFile")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "增加一级性别路径")
    public Response<Boolean> moveFile() {
        workspaceService.moveFile();
        return Response.success(true);
    }

    @GetMapping("/maleDataInsert")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "男装数据入库入minio")
    public Response<Boolean> maleDataInsert() throws FileNotFoundException {
//        workspaceService.maleDataInsert();
        return Response.success(true);
    }

    @PostMapping("styleList")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "获取style列表")
    public Response<List<StyleVO>> styleList() {
        return Response.success(workspaceService.styleList());
    }

    @PostMapping("/saveOrUpdateProject")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增或编辑", notes = "传入project")
    public Response saveOrUpdateProject(@Valid @RequestBody ProjectDTO projectDTO) {
        return Response.success(workspaceService.saveOrUpdateProject(projectDTO));
    }
}
