package com.fzm.mall.server.admin.message.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fzm.mall.server.admin.home_page.enums.type.AdminTypeEnum;
import com.fzm.mall.server.admin.home_page.service.IAdminService;
import com.fzm.mall.server.admin.message.entity.dto.ModifySmsTemplateDTO;
import com.fzm.mall.server.admin.message.entity.dto.SmsTemplateDTO;
import com.fzm.mall.server.admin.message.entity.vo.SmsTemplateVO;
import com.fzm.mall.server.admin.message.service.ISmsTemplateService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangp
 * @date 2021/4/29 15:53
 * @description 短信模板
 * @since JDK 1.8
 */
@Api(tags = "消息中心-短信模板")
@RestController
@RequestMapping("/smsTemplate")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SmsTemplateController {
    private final IAdminService adminService;
    private final ISmsTemplateService smsTemplateService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "新增")
//    @AdminLog(description = "财务中心-新增商户收付款方式", module = OperateModuleEnum.FINANCE_CENTER)
    @PostMapping("/add")
    public ResponseVO<String> add(@RequestBody SmsTemplateDTO dto, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getMerchantTypeArr());
        smsTemplateService.add(dto);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public ResponseVO<IPage<SmsTemplateVO>> page(
            @ApiParam(name = "templateCode", value = "模板编号")
            @RequestParam(required = false) String templateCode,
            @ApiParam(name = "templateName", value = "模板名称")
            @RequestParam(required = false) String templateName,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        IPage<SmsTemplateVO> page = smsTemplateService.page(templateCode, templateName, pageNum, pageSize);
        return resFac.getSuccessResponseWithData(page);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete/{templateCode}")
    public ResponseVO<String> delete(@PathVariable String templateCode, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getMerchantTypeArr());
        smsTemplateService.delete(templateCode);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "修改")
    @PostMapping("/modify")
    public ResponseVO<String> modify(@RequestBody ModifySmsTemplateDTO dto, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getMerchantTypeArr());
        smsTemplateService.modify(dto);
        return resFac.getSimpleSuccessResponse();
    }
}
