package com.miaxis.app.controller.tms;


import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.tms.domain.CoachInfo;
import com.miaxis.tms.dto.CoachInfoDTO;
import com.miaxis.tms.dto.CoachInfoIdDTO;
import com.miaxis.tms.dto.CoachInfoPwDTO;
import com.miaxis.tms.service.ICoachInfoService;
import com.miaxis.tms.vo.CoachInfoQRVo;
import com.miaxis.tms.vo.CoachInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 学员基本信息表 前端控制器
 * </p>
 *
 * @since 2021-03-09
 */
@RestController
@Api(tags = "【app-教练员】")
@RequestMapping(Constants.OPEN_PREFIX + "/tms/coachInfo")
public class CoachInfoController extends BaseController {

    @Autowired
    private ICoachInfoService coachInfoService;


    /**
     * 获取用户id获取详细信息
     */
    @GetMapping("/getCoachInfo")
    @ApiOperation("获取教练员详细信息")
    public Response<CoachInfoVo> getCoachInfo(CoachInfoIdDTO coaIdDto) {
        return Response.success(coachInfoService.getCoachInfoById(coaIdDto));
    }


    /**
     * 获取教练员生成二维码信息
     */
    @GetMapping("/getCoachQrInfo")
    @ApiOperation("获取教练员生成二维码信息")
    public Response<CoachInfoQRVo> getCoachQrInfo(CoachInfoIdDTO coaIdDto) {
        CoachInfoVo coachInfoVo = coachInfoService.getCoachInfoById(coaIdDto);
        CoachInfoQRVo qrVo = new CoachInfoQRVo();
        BeanUtils.copyProperties(coachInfoVo,qrVo);
        return Response.success(qrVo);
    }

    /**
     * 教练登录测试
     */
    @GetMapping("/coachInfoLogin")
    @ApiOperation("教练登录")
    public Response<CoachInfo> coachInfoLogin(CoachInfoDTO coaDto) {
        CoachInfo coachInfo = coachInfoService.getCoachBylogin(coaDto);
        if(coachInfo==null) {
            Response response = new Response(502,"用户不存在或用户密码错误");
            return response;

        }
        return Response.success(coachInfoService.getCoachBylogin(coaDto));
    }


    /**
     * 教练修改密码
     */
    @PutMapping("/updateCoachPassword")
    @ApiOperation("教练修改密码")
    public Response<CoachInfo> updateCoachPassword(CoachInfoPwDTO coaPwDto) {
        return coachInfoService.updateCoachPassword(coaPwDto);
    }

}

