package com.yonge.cooleshow.teacher.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch;
import com.yonge.cooleshow.biz.dal.entity.CourseScheduleReplied;
import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
import com.yonge.cooleshow.biz.dal.service.CourseRepliedService;
import com.yonge.cooleshow.biz.dal.support.PageUtil;
import com.yonge.cooleshow.biz.dal.vo.CourseRepliedVo;
import com.yonge.cooleshow.biz.dal.vo.MyRepliedVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.mybatis.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: cy
 * @Date: 2022/4/12
 */
@Api(tags = "陪练课")
@RestController
@RequestMapping("/courseReplied")
public class CourseRepliedController extends BaseController {
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private CourseRepliedService repliedService;

    @ApiOperation(value = "首页-我的课程-课程详情-评价陪练课", httpMethod = "POST", consumes = "application/json", produces = "application/json")
    @PostMapping(value = "/replied", consumes = "application/json", produces = "application/json")
    public HttpResponseResult<Object> replied(@Validated @RequestBody CourseScheduleReplied replied) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }

        replied.setCourseGroupType(CourseScheduleEnum.PRACTICE.getCode());
        repliedService.replied(replied,sysUser);
        return succeed();
    }

    @ApiOperation(value = "首页-我的课程-课程详情-查询陪练课评价")
    @PostMapping(value = "/selectReplied")
    public HttpResponseResult<CourseRepliedVo> selectReplied(@Validated @RequestBody CourseScheduleReplied replied) {
        replied.setCourseGroupType(CourseScheduleEnum.PRACTICE.getCode());
        return succeed(repliedService.selectReplied(replied));
    }

    @ApiOperation(value = "首页-我收到的评价")
    @PostMapping(value = "/myReplied")
    public HttpResponseResult<PageInfo<MyRepliedVo>> myReplied(@RequestBody MyCourseSearch search) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }
        search.setTeacherId(sysUser.getId());
        IPage<MyRepliedVo> pages = repliedService.myReplied(PageUtil.getPage(search), search);
        return succeed(PageUtil.pageInfo(pages));
    }
}