package com.ym.mec.teacher.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.ApprovalStatus;
import com.ym.mec.biz.dal.entity.MusicGroupQuit;
import com.ym.mec.biz.service.MusicGroupService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;

@RequestMapping("musicGroup")
@Api(tags = "乐团服务")
@RestController
public class MusicGroupController extends BaseController {

    @Resource
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private MusicGroupService musicGroupService;

    @ApiOperation(value = "申请退团")
    @PostMapping("/quitMusicGroup")
    @ApiImplicitParams({@ApiImplicitParam(name = "musicGroupId", value = "乐团id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "studentId", value = "学员编号", required = true, dataType = "Integer")})
    public HttpResponseResult quitMusicGroup(String musicGroupId, Integer studentId){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		MusicGroupQuit musicGroupQuit = new MusicGroupQuit();
		musicGroupQuit.setUserId(studentId);
		musicGroupQuit.setMusicGroupId(musicGroupId);
        musicGroupQuit.setApplyUserId(sysUser.getId());
		musicGroupQuit.setStatus(ApprovalStatus.PROCESSING);
        return succeed(musicGroupService.applyQuitMusicGroup(null, musicGroupQuit, sysUser.getId()));
    }
}
