/*
 * *************************************************
 * Copyright (c) 2018 QMTH. All Rights Reserved.
 * Created by Deason on 2018-07-18 10:38:43.
 * *************************************************
 */

package cn.com.qmth.examcloud.app.controller;

import cn.com.qmth.examcloud.app.model.Result;
import cn.com.qmth.examcloud.app.service.NetExamService;
import cn.com.qmth.examcloud.app.service.SmsService;
import cn.com.qmth.examcloud.app.service.UserAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统服务相关接口
 *
 * @version v1.0
 * @author: fengdesheng
 * @since: 2018/7/16
 */
@RestController
@RequestMapping("/api/v2")
@Api(tags = "系统服务相关接口")
public class SystemRestController {
    @Autowired
    private NetExamService netExamService;
    @Autowired
    private UserAuthService userAuthService;
    @Autowired
    private SmsService smsService;

    @ApiOperation(value = "获取服务器当前时间接口")
    @RequestMapping(value = "/system/currentTime", method = {RequestMethod.GET, RequestMethod.POST})
    public Result getCurrentTime(@RequestHeader String key, @RequestHeader String token) throws Exception {
        return netExamService.getCurrentTime(key, token);
    }

    @ApiOperation(value = "获取短信验证码接口")
    @RequestMapping(value = "/send/sms/code", method = {RequestMethod.GET, RequestMethod.POST})
    public Result sendSmsCode(@RequestParam String phone) throws Exception {
        //return smsService.sendSmsCode(key, token, phone);
        return userAuthService.sendSmsCode(phone);
    }

    @ApiOperation(value = "校验短信验证码接口", hidden = true)
    @RequestMapping(value = "/check/sms/code", method = {RequestMethod.GET, RequestMethod.POST})
    public Result checkSmsCode(@RequestHeader String key, @RequestHeader String token, @RequestParam String phone, @RequestParam String code) throws Exception {
        return smsService.checkSmsCode(key, token, phone, code);
    }

}