package cn.com.tenlion.buildingpictures.controller.apis.picturestemplate;

import cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplate.PicturesTemplateDTO;
import cn.com.tenlion.buildingpictures.pojo.vos.picturestemplate.PicturesTemplateContentVO;
import cn.com.tenlion.buildingpictures.pojo.vos.picturestemplate.PicturesTemplateVO;
import cn.com.tenlion.buildingpictures.service.picturestemplate.IPicturesTemplateService;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.component.SecurityComponent;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.CurrentUserIdInfoDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: PicturesTemplateController
 * @Description: 图片套版的模板管理
 * @Author: WenG
 * @Date: 2020-10-20 10:49
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "图片套版的模板管理接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/picturestemplate")
public class PicturesTemplateController extends DefaultBaseController {

    @Autowired
    private IPicturesTemplateService picturesTemplateService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "生成模板预览图", notes = "生成模板预览图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateCode", value = "picturesTemplateCode", paramType = "String", example = "模板编码")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("buiderpicturestemplate/{picturesTemplateCode}")
    public SuccessResult buiderPicturesTemplate(@PathVariable("picturesTemplateCode") String picturesTemplateCode) throws Exception {
        return picturesTemplateService.buiderPicturesTemplate(picturesTemplateCode);
    }

    @ApiOperation(value = "复制新的模板", notes = "复制新的模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "String", example = ""),
            @ApiImplicitParam(name = "picturesTemplateCode", value = "picturesTemplateCode", paramType = "String", example = "新的编码"),
            @ApiImplicitParam(name = "picturesTemplateTitle", value = "picturesTemplateTitle", paramType = "String", example = "新的标题")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("copypicturestemplate/{id}/{picturesTemplateCode}/{picturesTemplateTitle}")
    public SuccessResult copyPicturesTemplate(@PathVariable("id") String id, @PathVariable("picturesTemplateCode") String picturesTemplateCode, @PathVariable("picturesTemplateTitle") String picturesTemplateTitle) throws Exception {
        return picturesTemplateService.copyPicturesTemplate(id, picturesTemplateCode, picturesTemplateTitle);
    }

    @ApiOperation(value = "更改显示开关状态", notes = "更改显示开关状态")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatepicturestemplatepublishstatus/{picturesTemplateId}/{picturesTemplatePublishStatus}")
    @CheckRequestBodyAnnotation
    public SuccessResult updatePicturesTemplatePublishStatus(@PathVariable("picturesTemplateId") String picturesTemplateId, @PathVariable("picturesTemplatePublishStatus") Boolean picturesTemplatePublishStatus) throws Exception {
        return picturesTemplateService.updatePicturesTemplatePublishStatus(picturesTemplateId, picturesTemplatePublishStatus);
    }

    @ApiOperation(value = "新增图片套版的模板管理", notes = "新增图片套版的模板管理接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("savepicturestemplate")
    @CheckRequestBodyAnnotation
    public SuccessResult savePicturesTemplate(@RequestBody PicturesTemplateVO picturesTemplateVO) throws Exception {
        return picturesTemplateService.savePicturesTemplate(picturesTemplateVO);
    }

    @ApiOperation(value = "删除图片套版的模板管理(id列表)", notes = "删除图片套版的模板管理(id列表)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID列表，用下划线分隔", paramType = "path", example = "1_2_3")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("removepicturestemplate/{ids}")
    public SuccessResult removePicturesTemplate(@PathVariable("ids") String ids) throws RemoveException {
        return picturesTemplateService.removePicturesTemplate(ids);
    }


    @ApiOperation(value = "修改图片套版的代码", notes = "修改图片套版的代码接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateId", value = "图片套版的模板管理ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatepicturesmodulecontent/{picturesTemplateId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updatePicturesTemplateContent(@PathVariable("picturesTemplateId") String picturesTemplateId, @RequestBody PicturesTemplateContentVO picturesTemplateContentVO) throws Exception {
        return picturesTemplateService.updatePicturesTemplateContent(picturesTemplateId, picturesTemplateContentVO);
    }

    @ApiOperation(value = "修改图片套版的模板管理", notes = "修改图片套版的模板管理接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateId", value = "图片套版的模板管理ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatepicturestemplate/{picturesTemplateId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updatePicturesTemplate(@PathVariable("picturesTemplateId") String picturesTemplateId, @RequestBody PicturesTemplateVO picturesTemplateVO) throws Exception {
        return picturesTemplateService.updatePicturesTemplate(picturesTemplateId, picturesTemplateVO);
    }

    @ApiOperation(value = "图片套版的模板管理详情(通过ID)", notes = "图片套版的模板管理详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateId", value = "图片套版的模板管理ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getpicturestemplatebyid/{picturesTemplateId}")
    public PicturesTemplateDTO getPicturesTemplateById(@PathVariable("picturesTemplateId") String picturesTemplateId) throws SearchException {
        return picturesTemplateService.getPicturesTemplateById(picturesTemplateId);
    }

    @ApiOperation(value = "图片套版的模板管理列表", notes = "图片套版的模板管理列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpicturestemplate")
    public List<PicturesTemplateDTO> listPicturesTemplate() throws SearchException {
        Map<String, Object> params = requestParams();
        return picturesTemplateService.listPicturesTemplate(params);
    }

    @ApiOperation(value = "图片套版的模板管理分页列表", notes = "图片套版的模板管理分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpagepicturestemplate")
    public SuccessResultList<List<PicturesTemplateDTO>> listPagePicturesTemplate(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return picturesTemplateService.listPagePicturesTemplate(page);
    }

    @ApiOperation(value = "图片套版的模板管理统计", notes = "图片套版的模板管理统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("countpicturestemplate")
    SuccessResultData<Integer> countPicturesTemplate() throws SearchException {
        Map<String, Object> params = requestParams();
        return picturesTemplateService.countPicturesTemplate(params);
    }

    @ApiOperation(value = "当前用户id信息", notes = "当前用户id信息接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getcurrentuseridinfo")
    public CurrentUserIdInfoDTO getCurrentUserIdInfo() {
        return securityComponent.getCurrentUserIdInfo();
    }

}