package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxMallApply;
import com.iformall.domain.po.WxMsgValidationcode;
import com.iformall.service.WxMallApplyService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wxMallApply")
public class WxMallApplyController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxMallApplyService wxMallApplyService;

    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData list(@ModelAttribute WxMallApply wxMallApply, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxMallApplyController::list");
        if (null == wxMallApply) wxMallApply = new WxMallApply();
        final PageInfo<WxMallApply> page = wxMallApplyService.listAsPage(wxMallApply, pageNum, pageSize);
        return new ResultData(page);
    }

    @PostMapping("add")
    public ResultData add(@RequestBody WxMallApply wxMallApply) {
        logger.debug("[" + getIpAddr() + "] WxMallApplyController::add");
        //Assert.notNull(wxMallApply.getName(), "角色名不能为空");
        //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
        return wxMallApplyService.saveOrUpdate(wxMallApply);

    }

    @PostMapping("update")
    public ResultData update(@RequestBody WxMallApply wxMallApply) {
        logger.debug("[" + getIpAddr() + "] WxMallApplyController::update");
        return wxMallApplyService.saveOrUpdate(wxMallApply);
    }

    @GetMapping("/del")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true)
    public ResultData delete(String id) {
        logger.debug("[" + getIpAddr() + "] WxMallApplyController::delete");
        wxMallApplyService.deleteById(id);
        return new ResultData(Result.SUCCESS, "删除成功", null);
    }

    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true)
    public ResultData findById(String id) {
        logger.debug("[" + getIpAddr() + "] WxMallApplyController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxMallApplyService.getById(id));
    }


    @GetMapping("/sendvalidationcode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true)})
    public ResultData sendvalidationcode(String phone, Integer type) {
        logger.debug("[" + getIpAddr() + "] WxMallApplyController::sendvalidationcode");
        WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode();
        wxMsgValidationcode.setTenantId("1");
        wxMsgValidationcode.setPhone(phone);
        wxMsgValidationcode.setType(type);
        return wxMallApplyService.sendvalidationcode(wxMsgValidationcode);
    }


}
