package com.ym.mec.web.controller;

import com.ym.mec.common.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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;

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

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private ClassGroupService classGroupService;

    @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 = "删除教师")
    @PostMapping("/delete/{userId}")
    public Object update(@PathVariable("userId") Long userId) {
        teacherService.deleteTeacher(userId);
        return succeed();
    }

    @ApiOperation(value = "根据教师编号查询教师基本信息")
    @GetMapping("/get/{id}")
    @ApiParam(value = "教师编号", required = true)
    public Object get(@PathVariable("id") 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/{id}")
    @ApiParam(value = "教师编号", required = true)
    public Object getClassGroup(@PathVariable("id") 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));
    }
}
