package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.Teacher;
import com.ym.mec.biz.dal.page.TeacherQueryInfo;
import com.ym.mec.biz.dal.page.VipClassQueryInfo;
import com.ym.mec.biz.service.ClassGroupService;
import com.ym.mec.biz.service.TeacherService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.QueryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RequestMapping("teacher")
@Api(tags = "教师服务")
@RestController
public class TeacherController extends BaseController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private ClassGroupService classGroupService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增教师")
    @PostMapping("/add")
    public Object add(Teacher teacher) {
        try {
            teacherService.add(teacher);
        } catch (Exception e) {
            e.printStackTrace();
            return failed(e.getMessage());
        }
        return succeed();
    }

    @ApiOperation(value = "修改教师")
    @PostMapping("/update")
    public Object update(Teacher teacher) {
        teacher.setUpdateTime(new Date());
        teacherService.updateTea(teacher);
        return succeed();
    }

    @ApiOperation(value = "根据教师编号查询教师基本信息")
    @GetMapping("/get")
    @ApiParam(value = "教师编号", required = true)
    public Object get(Integer id) {
        return succeed(teacherService.getDetail(id));
    }

    @ApiOperation(value = "分页查询教师列表")
    @GetMapping("/queryPage")
    public Object queryPage(TeacherQueryInfo queryInfo) {
        return succeed(teacherService.queryPageDetail(queryInfo));
    }

    @ApiOperation(value = "根据教师编号查询教师课程班列表")
    @GetMapping("/getClass")
    @ApiParam(value = "教师编号", required = true)
    public Object getClassGroup(Integer id) {
        return succeed(classGroupService.findClassGroup4Teacher(id));
    }

    @ApiOperation(value = "获取老师乐团课程信息列表")
    @GetMapping("/getTeacherMusicClass")
    @ApiParam(value = "教师编号", required = true)
    public Object getTeacherMusicClass(Integer teacherId){
        return succeed(classGroupService.getTeacherMusicClass(teacherId));
    }

    @ApiOperation(value = "获取老师VIP课程信息列表")
    @GetMapping("/getTeacherVipClass")
    public Object getTeacherVipClass(VipClassQueryInfo queryInfo){
        return succeed(classGroupService.getTeacherVipClass(queryInfo));
    }

    @ApiOperation(value = "获取教师所有聊天群组")
    @GetMapping("/queryTeacherGroups")
    public Object queryTeacherGroups(String search){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            return failed("获取用户信息失败");
        }
        return succeed(teacherService.queryTeacherGroups(sysUser.getId(),search));
    }

    @ApiOperation(value = "获取和当前教师相关的所有学员聊天列表")
    @GetMapping("/queryGroupStudents")
    public Object queryGroupStudents(String search){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            return failed("获取用户信息失败");
        }
        return succeed(teacherService.queryGroupStudents(sysUser.getId(),search));
    }

}
