package com.njcn.csdevice.controller.project;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.pojo.po.CsTopologyDiagramTemplate;
import com.njcn.csdevice.pojo.vo.CsTopologyDiagramTemplateVO;
import com.njcn.csdevice.service.CsTopologyDiagramTemplateService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
* (cs_line_topology_template)表控制层
*
* @author xxxxx
*/
@RestController
@Slf4j
@RequestMapping("/topologyTemplate")
@Api(tags = " 拓扑图模板")
@AllArgsConstructor
public class TopologyTemplateController extends BaseController {

    private final CsTopologyDiagramTemplateService csTopologyDiagramTemplateService;
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
    @PostMapping("/uploadImage")
    @ApiOperation("上传模板底图")
    @ApiImplicitParam(name = "file", value = "底图文件", required = true)
    public HttpResult<CsTopologyDiagramTemplate> uploadImage(@RequestParam("file") MultipartFile issuesFile){
        String methodDescribe = getMethodDescribe("uploadImage");
        CsTopologyDiagramTemplate csTopologyDiagramTemplate = csTopologyDiagramTemplateService.uploadImage(issuesFile);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,csTopologyDiagramTemplate, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryImage")
    @ApiOperation("查询拓扑图模板")
    public HttpResult<List<CsTopologyDiagramTemplateVO>> queryImage(){
        String methodDescribe = getMethodDescribe("queryImage");

        List<CsTopologyDiagramTemplateVO> list = csTopologyDiagramTemplateService.queryImage();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deleteImage")
    @ApiOperation("删除拓扑图模板")
    public HttpResult<Boolean> deleteImage(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("deleteImage");

        Boolean flag = csTopologyDiagramTemplateService.deleteImage(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
}
