package com.yonge.cooleshow.website.controller;

import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
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 com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupService;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonShelvesVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;

/**
 * 视频课基本信息表 web 控制层
 *
 **/
@RestController
@RequestMapping("/videoLessonGroup")
@Api(tags = "视频课组")
public class VideoLessonGroupController extends BaseController {
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private VideoLessonGroupService videoLessonGroupService;

    /**
     * @Description: 更新上架状态
     * @Author: cy
     * @Date: 2022/4/25
     */
    @ApiOperation(value = "更新上架状态", httpMethod = "POST", consumes = "application/json", produces = "application/json")
    @PostMapping(value = "/updateShelves", consumes = "application/json", produces = "application/json")
    public HttpResponseResult<Object> updateShelves(@Validated @RequestBody VideoLessonShelvesVo shelvesVo) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        if (shelvesVo.getShelvesFlag() != 0) {
            return failed("只能做下架操作");
        }
        /*if (shelvesVo.getShelvesFlag() == 0 && StringUtil.isEmpty(shelvesVo.getShelvesReason())) {
            return failed("下架必须要有下架原因");
        }*/

        shelvesVo.setShelvesId(user.getId());
        shelvesVo.setShelvesTime(new Date());

        shelvesVo.setClientType(ClientEnum.WEBSITE);
        videoLessonGroupService.updateShelves(shelvesVo);
        return succeed();
    }

	}
