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.service.CoursesGroupService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2020/3/8
 */
@Api(tags = "对外课程组服务")
@RequestMapping("courseGroup")
@RestController
public class CourseGroupController extends BaseController {

    @Autowired
    private CoursesGroupService coursesGroupService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "获取课程组详情")
    @GetMapping("/getGroupDetail")
    public HttpResponseResult getGroupDetail(Long groupId){
        return succeed(coursesGroupService.getGroupDetail(groupId));
    }

    @ApiOperation(value = "购买课程组")
    @PostMapping("/buyCourseGroup")
    public HttpResponseResult buyCourseGroup(Long courseGroupId, boolean isUseBalancePayment) throws Exception {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        return coursesGroupService.buyCourseGroup(sysUser.getId(), courseGroupId, isUseBalancePayment);
    }

}
