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.StudentDao;
import com.ym.mec.biz.dal.dto.ChildrenDayDetailDto;
import com.ym.mec.biz.dal.entity.ChildrenDayDegreeDetail;
import com.ym.mec.biz.dal.entity.Student;
import com.ym.mec.biz.service.ChildrenDayDegreeDetailService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@RequestMapping("childrenDayDegreeDetail")
@Api(tags = "6.1儿童节活动报名详情")
@RestController
public class ChildrenDayDegreeDetailController extends BaseController {
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private ChildrenDayDegreeDetailService childrenDayDegreeDetailService;
    @Autowired
    private StudentDao studentDao;

    @ApiOperation(value = "获取用户已报名的详情,类型 1-乐器考级 2-乐理考级 3-vip1v1,4-vip1v2 5-乐理课")
    @GetMapping("/getUserDegreeInfo")
    public HttpResponseResult<ChildrenDayDetailDto> getFeeInfo() {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (Objects.isNull(user)) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        List<ChildrenDayDegreeDetail> userDegreeInfo = childrenDayDegreeDetailService.getUserDegreeInfo(user.getId());
        ChildrenDayDetailDto childrenDayDetailDto = new ChildrenDayDetailDto();
        childrenDayDetailDto.setUser(user);
        childrenDayDetailDto.setChildrenDayDegreeDetails(userDegreeInfo);
        Student student = studentDao.get(user.getId());
        if (student != null && StringUtils.isNotBlank(student.getSubjectIdList())) {
            List<String> subjectIds = Arrays.asList(student.getSubjectIdList().split(","));
            childrenDayDetailDto.setSubjectId(Integer.parseInt(subjectIds.get(0)));
        }
        return succeed(childrenDayDetailDto);
    }

}
