package com.cweb.controller;

import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.MessageConfig;
import com.hai.model.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


@Controller
@Api(value = "短信接口")
@RequestMapping(value = "/SendSms")
public class SendSmsController {

    private static Logger log = LoggerFactory.getLogger(SendSmsController.class);

    @Resource
    private MessageConfig messageConfig;

    @RequestMapping(value = "/sendSmsCodeByHw", method = RequestMethod.GET)
    @ApiOperation(value = "发送短信验证码")
    @ResponseBody
    public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone,
                                    @RequestParam(value = "HWMSG", required = true) Integer HWMSG) {
        try {

            String smsMsgId;

            switch (HWMSG) {
                case 1 :
                    smsMsgId = MessageConfig.HWMSG_ID1;
                    break;
                case 2 :
                    smsMsgId = MessageConfig.HWMSG_ID2;
                    break;
                case 3 :
                    smsMsgId = MessageConfig.HWMSG_ID3;
                    break;
                case 5 :
                    smsMsgId = MessageConfig.HWMSG_ID5;
                case 6 :
                    smsMsgId = MessageConfig.HWMSG_ID6;
                    break;
                default :
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂无当前模版");
            }

            return ResponseMsgUtil.success(messageConfig.sendSmsCodeHw(phone , smsMsgId));
        } catch (Exception e) {
            log.error("CmsContentController --> sendSmsCode() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }



}
