package com.simuwang.manage.api.template;

import com.simuwang.base.common.support.MybatisPage;
import com.simuwang.base.pojo.dto.query.EmailTemplateInfoPageQuery;
import com.simuwang.base.pojo.dto.query.EmailTemplateSettingPageQuery;
import com.simuwang.base.pojo.vo.*;
import com.simuwang.logging.SystemLog;
import com.simuwang.manage.service.EmailTemplateInfoService;
import com.simuwang.manage.service.EmailTemplateMappingService;
import com.smppw.common.pojo.ResultVo;
import com.smppw.common.pojo.enums.status.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 模版设置
 * Author:   chenjianhua
 * Date:     2024/9/25 18:46
 * Description: ${DESCRIPTION}
 */
@SystemLog(value = "模版管理")
@RestController
@RequestMapping("/v1/template-setting")
public class TemplateSettingController {

    @Autowired
    private EmailTemplateMappingService emailTemplateMappingService;

    /**
     * 模版设置页面展示数据
     * @param emailTemplateSettingPageQuery
     * @return
     */
    @SystemLog(value = "模版设置页面展示数据")
    @RequestMapping("search-template-setting-list")
    public MybatisPage<EmailTemplateMappingVO> searchTemplateSettingList(EmailTemplateSettingPageQuery emailTemplateSettingPageQuery){
        MybatisPage<EmailTemplateMappingVO> result = emailTemplateMappingService.searchTemplateSettingList(emailTemplateSettingPageQuery);
        return result;
    }


    /**
     * 批量删除模版设置
     * @param idListVO
     * @return
     */
    @SystemLog(value = "批量删除模版设置",type = SystemLog.Type.DELETE)
    @RequestMapping("delete-template-setting")
    public boolean deleteTemplateSetting(@RequestBody IdListVO idListVO){
        emailTemplateMappingService.deleteTemplateSetting(idListVO);
        return true;
    }


    /**
     * 保存模版设置
     * @param emailTemplateMappingVO
     * @return
     */
    @SystemLog(value = "保存模版设置",type = SystemLog.Type.INSERT)
    @RequestMapping("save-template-setting")
    public boolean saveTemplateSetting(@RequestBody EmailTemplateMappingVO emailTemplateMappingVO){
        emailTemplateMappingService.saveTemplateSetting(emailTemplateMappingVO);
        return true;
    }

    /**
     * 开启关闭状态
     * @param statusVO
     * @return
     */
    @SystemLog(value = "开启关闭状态", type = SystemLog.Type.UPDATE)
    @PostMapping("control-template-status")
    public ResultVo controlTemplateSetting(@RequestBody StatusVO statusVO){
        ResultVo vo = new ResultVo(ResultCode.SAVE_SUCCESS.getCode());
        try{
            emailTemplateMappingService.controlTemplateConfig(statusVO);
            vo.setData(true);
        }catch (Exception e){
            vo.setCode(ResultCode.SAVE_FAILED.getCode());
            vo.setData(false);
        }
        return vo;
    }

    /**
     * 模版设置编辑查询
     * @param idVO
     * @return
     */
    @SystemLog(value = "模版设置编辑查询")
    @GetMapping("search-template-setting")
    public ResultVo searchTemplateSetting(IdVO idVO){
        ResultVo vo = new ResultVo(ResultCode.SAVE_SUCCESS.getCode());
        try{
            EmailTemplateMappingVO emailTemplateMappingVO = emailTemplateMappingService.searchTemplateSetting(idVO.getId());
            vo.setData(emailTemplateMappingVO);
        }catch (Exception e){
            vo.setCode(ResultCode.SAVE_FAILED.getCode());
            vo.setData(false);
        }
        return vo;
    }
}
