package com.wgb.system.service.controller;

import com.data.model.restful.response.InternalResponse;
import com.wgb.system.service.domain.response.LayuiTableResponse;
import com.wgb.system.service.service.SysService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RequestMapping("/sys")
@RestController
public class SysConteoller {

    private final SysService sysService;

    public SysConteoller(SysService sysService) {
        this.sysService = sysService;
    }

    @ApiOperation(value = "/获取菜单", response = LayuiTableResponse.class)
    @RequestMapping(value = "/getMenu",method = RequestMethod.POST)
    public InternalResponse getMenu(){
        return InternalResponse.success().withBody(sysService.getMenuList());
    }

    @ApiOperation(value = "/发送订单短信给师傅", response = LayuiTableResponse.class)
    @ResponseBody
    @RequestMapping(value = "/sendBusinessSms",method = {RequestMethod.GET})
    public InternalResponse sendBusinessSms(@RequestParam String userCellphone,@RequestParam String smsType)throws Exception{
        log.info("Start to execute /sys/sendBusinessSms with, userCellphone ={}, smsType={}", userCellphone,smsType);
        String code= sysService.sendBusinessSms(userCellphone,smsType);
        log.info("Return object for /business/getList is result={}", code);
        return InternalResponse.success().withBody(code);
    }

    @ApiOperation(value = "/发送短信", response = LayuiTableResponse.class)
    @ResponseBody
    @RequestMapping(value = "/sendSms",method = {RequestMethod.GET})
    public InternalResponse sendSms(@RequestParam String userCellphone,@RequestParam String smsType)throws Exception{
        log.info("Start to execute /sys/sendSms with, userCellphone ={}, smsType={}", userCellphone,smsType);
        String code= sysService.sendLoginCodeSms(userCellphone,smsType);
        log.info("Return object for /sys/sendSms is result={}", code);
        return InternalResponse.success().withBody(code);
    }

    @ApiOperation(value = "/检查验证码", response = InternalResponse.class)
    @ResponseBody
    @RequestMapping(value = "/inspectSms",method = {RequestMethod.GET})
    public InternalResponse inspectSms(@RequestParam String userCellphone,@RequestParam String smsCode,@RequestParam String smsType){
        log.info("Start to execute /sys/inspectSms with, userCellphone ={}, smsType={}", userCellphone,smsType);
        sysService.inspectSms(userCellphone,smsCode,smsType);
        log.info("Return object for /sys/inspectSms is result={}", "true");
        return InternalResponse.success();
    }

    @ApiOperation(value = "/提交文件", response = InternalResponse.class)
    @ResponseBody
    @RequestMapping(value = "/pushFile",method = {RequestMethod.POST})
    public InternalResponse pushFile(@RequestPart(value="file", required = true) final MultipartFile file)throws Exception{
        log.info("Start to execute /sys/pushFile with, userCellphone ={}, smsType={}", file.getName());
       String path= sysService.pushFile(file);
        log.info("Return object for /sys/inspectSms is result={}", path);
        return InternalResponse.success().withBody(path);
    }
}

