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.vo.SmsSendVO;
import com.fzm.mall.server.admin.message.service.ISmsSendService;
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/5/7 10:34
 * @description 短信消息列表
 * @since JDK 1.8
 */
@Api(tags = "消息中心-SMS消息列表")
@RestController
@RequestMapping("/smsList")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SmsListController {
    private final IAdminService adminService;
    private final ISmsSendService smsSendService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public ResponseVO<IPage<SmsSendVO>> page(
            @ApiParam(name = "smsNo", value = "消息编号")
            @RequestParam(required = false) String smsNo,
            @ApiParam(name = "keyWord", value = "消息关键字")
            @RequestParam(required = false) String keyWord,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        IPage<SmsSendVO> page = smsSendService.page(smsNo, keyWord, pageNum, pageSize);
        return resFac.getSuccessResponseWithData(page);
    }

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

    @ApiOperation(value = "重发")
//    @AdminLog(description = "财务中心-新增商户收付款方式", module = OperateModuleEnum.FINANCE_CENTER)
    @GetMapping("/reSend/{smsNo}")
    public ResponseVO<String> reSend(@PathVariable String smsNo, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getMerchantTypeArr());
        smsSendService.reSend(smsNo);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "立即发送")
//    @AdminLog(description = "财务中心-新增商户收付款方式", module = OperateModuleEnum.FINANCE_CENTER)
    @PostMapping("/sendNow/{smsNo}")
    public ResponseVO<String> sendNow(@PathVariable String smsNo, @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getMerchantTypeArr());
//        smsSendService.send(dto);
        return resFac.getSimpleSuccessResponse();
    }
}
