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.entity.CloudCoachPaymentProgram;
import com.ym.mec.biz.dal.entity.MemberRankSetting;
import com.ym.mec.biz.dal.entity.StudentCloudCoachPaymentDetails;
import com.ym.mec.biz.service.CloudCoachPaymentProgramService;
import com.ym.mec.biz.service.MemberRankSettingService;
import com.ym.mec.biz.service.StudentCloudCoachPaymentDetailsService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.exception.BizException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "团练宝缴费项目")
@RequestMapping("cloudCoachPaymentProgram")
@RestController
public class CloudCoachPaymentProgramController extends BaseController {

    @Autowired
    private CloudCoachPaymentProgramService cloudCoachPaymentProgramService;
    @Autowired
    private MemberRankSettingService memberRankSettingService;
    @Autowired
    private StudentCloudCoachPaymentDetailsService studentCloudCoachPaymentDetailsService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "获取明细")
    @PostMapping("/get")
    public Object get(Long id){
        CloudCoachPaymentProgram cloudCoachPaymentProgram = cloudCoachPaymentProgramService.get(id);
        if(cloudCoachPaymentProgram == null){
            throw new BizException("云教练缴费项目不存在，请联系指导老师");
        }
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        StudentCloudCoachPaymentDetails studentCloudCoachPaymentDetails = studentCloudCoachPaymentDetailsService.findByUserId(id, sysUser.getId());
        if(studentCloudCoachPaymentDetails == null){
            throw new BizException("您不在当前云教练缴费项目中，请联系指导老师");
        }
        MemberRankSetting memberRankSetting = memberRankSettingService.get(cloudCoachPaymentProgram.getMemberRankSettingId());
        cloudCoachPaymentProgram.setMemberIntro(memberRankSetting.getIntro());
        return succeed(cloudCoachPaymentProgram);
    }
}
