package com.ym.mec.student.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dao.TempLiveTeacherCardDao;
import com.ym.mec.biz.dal.entity.ImGroup;
import com.ym.mec.biz.dal.entity.Student;
import com.ym.mec.biz.dal.entity.Subject;
import com.ym.mec.biz.dal.entity.TempLiveTeacherCard;
import com.ym.mec.biz.service.ImGroupService;
import com.ym.mec.biz.service.StudentService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 直播临时活动
 */
@RequestMapping("tempLiveActivityController")
@Api(tags = "直播临时活动")
@RestController
public class TempLiveActivityController extends BaseController {
    @Resource
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private StudentService studentService;
    @Resource
    private TempLiveTeacherCardDao tempLiveTeacherCardDao;

    @ApiOperation("查询声部")
    @PostMapping(value = "/querySubjectOption", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public HttpResponseResult<Map<String, Object>> querySubjectOption() {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || user.getId() == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        Map<String, Object> res = new HashMap<>();
        List<Subject> options = tempLiveTeacherCardDao.querySubjectOption();
        res.put("options", options);

        Student student = studentService.get(user.getId());
        res.put("subjectId", student.getSubjectIdList());

        Integer goodsId = 4;
        Integer ststus = tempLiveTeacherCardDao.getJoinStstus(user.getId(), goodsId);
        res.put("ststus", ststus);

        String joinSubjectId = tempLiveTeacherCardDao.getJoinSubject(user.getId(),goodsId);
        res.put("joinSubjectId", joinSubjectId);

        return succeed(res);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "subjectId",
                    value = "声部id",
                    paramType = "query", dataType = "String", required = true
            )
    })
    @ApiOperation("查询声部上课老师名片信息列表")
    @PostMapping(value = "/listTeacherCard", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public HttpResponseResult<List<TempLiveTeacherCard>> listTeacherCard(@ApiIgnore @RequestBody TempLiveTeacherCard param) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || user.getId() == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        param.setStudentId(user.getId());
        List<TempLiveTeacherCard> list = tempLiveTeacherCardDao.list(param);
        return succeed(list);
    }
}
