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.dto.MusicGroupSubjectGoodsAndInfoDto;
import com.ym.mec.biz.dal.dto.RegisterPayDto;
import com.ym.mec.biz.dal.entity.*;
import com.ym.mec.biz.service.MusicGroupService;
import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
import com.ym.mec.biz.service.StudentRegistrationService;
import com.ym.mec.biz.service.SubjectService;
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.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@RequestMapping("register")
@Api(tags = "乐团注册")
@RestController
public class MusicGroupRegisterController extends BaseController {

    @Autowired
    private StudentRegistrationService studentRegistrationService;
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
    @Resource
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private MusicGroupService musicGroupService;


    @ApiOperation(value = "新增学生报名信息")
    @PostMapping("/add")
    public HttpResponseResult add(@RequestBody StudentRegistration studentRegistration) {
        MusicGroup musicGroup = musicGroupService.get(studentRegistration.getMusicGroupId());
        if (musicGroup == null) {
            return failed("乐团信息不存在");
        }
        StudentRegistration hasReg = studentRegistrationService.getByPhoneAndMusicGroupId(studentRegistration.getMusicGroupId(), studentRegistration.getParentsPhone());
        if (hasReg != null) {
            return failed("该乐团您已注册");
        }
        studentRegistration.setOrganId(musicGroup.getOrganId());
        return succeed(studentRegistrationService.addStudent(studentRegistration));
    }

    @ApiOperation(value = "获取乐团报名所需信息")
    @GetMapping("/getMusicGroupRegInfo")
    @ApiImplicitParams({@ApiImplicitParam(name = "musicGroupId", value = "乐团编号", required = true, dataType = "String")})
    public HttpResponseResult getMusicGroupRegInfo(String musicGroupId) {
        return succeed(musicGroupSubjectPlanService.getMusicGroupRegInfo(musicGroupId));
    }

}
