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.dto.BasicUserDto;
import com.ym.mec.biz.dal.dto.StudentVisitDto;
import com.ym.mec.biz.dal.entity.MusicGroup;
import com.ym.mec.biz.dal.entity.StudentRegistration;
import com.ym.mec.biz.dal.entity.StudentVisit;
import com.ym.mec.biz.dal.page.StudentVisitQueryInfo;
import com.ym.mec.biz.service.StudentVisitService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.List;

@Api(tags = "回访服务（老师）")
@RequestMapping("visit")
@RestController
public class VisitController extends BaseController {

    @Autowired
    private StudentVisitService studentVisitService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "回访列表")
    @GetMapping("/queryPage")
    public HttpResponseResult<PageInfo<StudentVisitDto>> queryPage(StudentVisitQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(studentVisitService.getPageList(queryInfo));
    }

    @ApiOperation(value = "添加回访")
    @PostMapping(value = "/add")
    public HttpResponseResult<StudentVisit> add(StudentVisit studentVisit) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        studentVisit.setTeacherId(sysUser.getId());
        studentVisit.setVisiterType(StudentVisit.VisiterTypeEnum.TEACHER);
        studentVisitService.addVisit(studentVisit);
        return succeed(studentVisit);
    }


    @ApiOperation(value = "回访详情")
    @GetMapping(value = "/getInfo")
    public HttpResponseResult<StudentVisitDto> getInfo(Integer id) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        StudentVisitDto info = studentVisitService.getInfo(id);
        if (!info.getTeacherId().equals(sysUser.getId())) {
            failed("请勿非法访问");
        }
        return succeed(studentVisitService.getInfo(id));
    }

    @ApiOperation(value = "获取乐团列表")
    @GetMapping(value = "/getMusicGroup")
    public HttpResponseResult<List<MusicGroup>> getMusicGroup() {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        return succeed(studentVisitService.getMusicGroup(sysUser.getId()));
    }

    @ApiOperation(value = "获取乐团老师教的学生列表")
    @GetMapping(value = "/getMusicGroupStu")
    public HttpResponseResult<List<StudentRegistration>> getMusicGroupStu(String musicGroupId) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        return succeed(studentVisitService.getMusicGroupStu(musicGroupId, sysUser.getId()));
    }

    @ApiOperation(value = "获取老师教的学生列表(带分页)")
    @GetMapping("/getStudents")
    public HttpResponseResult<PageInfo<BasicUserDto>> getStudents(StudentVisitQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(studentVisitService.getStudents(queryInfo));
    }
}
