package com.yonge.cooleshow.student.controller.open;

import com.yonge.cooleshow.biz.dal.service.StudentService;
import com.yonge.cooleshow.biz.dal.service.TeacherService;
import com.yonge.cooleshow.biz.dal.vo.TeacherVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.util.StringUtil;
import com.yonge.toolset.utils.string.ValueUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("/open")
@Api(value = "开放权限接口", tags = "开放权限接口")
public class OpenClient extends BaseController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private StudentService studentService;

    @ApiOperation(value = "查询老师头像昵称信息")
    @GetMapping("/getTeacher")
    public HttpResponseResult<TeacherVo> getTeacher(@ApiParam(value = "老师ID", required = true) @RequestParam("userId") Long userId) {
        if (null == userId) {
            return failed("缺少老师ID");
        }
        TeacherVo detail = teacherService.detail(userId);
        detail.setIdCardNo(ValueUtil.fuzzyIdCard(detail.getIdCardNo()));
        detail.setPhone(ValueUtil.fuzzyMobile(detail.getPhone()));
        return HttpResponseResult.succeed(detail);
    }

    @ApiOperation(value = "绑定老师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "老师id", required = true),
            @ApiImplicitParam(name = "isUpdate", value = "是否更新绑定老师", dataType = "Boolean")
    })
    @GetMapping("/bindTeacher")
    public HttpResponseResult<Map<String,TeacherVo>> bindTeacher(String phone, Long userId, Boolean isUpdate) {
        if (StringUtil.isEmpty(phone)) {
            return failed("缺少手机号");
        }
        if (null == userId) {
            return failed("缺少老师ID");
        }
        return studentService.bindTeacher(phone, userId, isUpdate);
    }
}
