package com.yonge.cooleshow.teacher.controller.open;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.search.ShareProfitParam;
import com.yonge.cooleshow.biz.dal.service.CourseGroupService;
import com.yonge.cooleshow.biz.dal.service.MemberPriceSettingsService;
import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupService;
import com.yonge.cooleshow.biz.dal.vo.ShareProfitVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.annotation.Resource;

@RestController
@RequestMapping("/open")
@Api(tags = "开放权限接口-分享")
public class OpenShareController extends BaseController {
    private final static Logger log = LoggerFactory.getLogger(OpenShareController.class);

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private VideoLessonGroupService videoLessonGroupService;

    @Autowired
    private MusicSheetService musicSheetService;

    @Autowired
    private MemberPriceSettingsService memberPriceSettingsService;

    /**
     * 服务对象
     */
    @Resource
    private CourseGroupService courseGroupService;

    @ApiOperation(value = "老师乐谱分享分润")
    @PostMapping(value="/musicShareProfit")
    public HttpResponseResult<ShareProfitVo> shareMusicSheetProfit(@RequestBody ShareProfitParam param) {
        SysUser sysUser = sysUserFeignService.queryUserById(param.getUserId());
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }
        return succeed(musicSheetService.shareMusicSheetProfit(sysUser,param.getBizId()));
    }


    @ApiOperation(value = "老师直播课分享分润")
    @PostMapping(value= "/liveShareProfit")
    public HttpResponseResult<ShareProfitVo> shareLiveCourseProfit(@RequestBody ShareProfitParam param) {
        SysUser sysUser = sysUserFeignService.queryUserById(param.getUserId());
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }
        return succeed(courseGroupService.shareLiveCourseProfit(sysUser, param.getBizId()));
    }



    @ApiOperation(value = "老师视频课分享分润")
    @PostMapping(value= "/videoShareProfit")
    public HttpResponseResult<ShareProfitVo> shareVideoCourseProfit(@RequestBody ShareProfitParam param) {
        SysUser sysUser = sysUserFeignService.queryUserById(param.getUserId());
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }
        return succeed(videoLessonGroupService.shareVideoCourseProfit(sysUser, param.getBizId()));
    }



    @ApiOperation(value = "老师VIP分享分润")
    @PostMapping(value="/vipProfit")
    public HttpResponseResult<ShareProfitVo> shareVipProfit(@RequestBody ShareProfitParam param) {
        SysUser sysUser = sysUserFeignService.queryUserById(param.getUserId());
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }
        return succeed(memberPriceSettingsService.shareVipProfit(sysUser,param.getBizId()));
    }
}
