package com.yonge.cooleshow.student.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.TeacherStyleSearch;
import com.yonge.cooleshow.biz.dal.enums.YesOrNoEnum;
import com.yonge.cooleshow.biz.dal.service.StudentStarService;
import com.yonge.cooleshow.biz.dal.service.TeacherService;
import com.yonge.cooleshow.biz.dal.service.TeacherStyleVideoService;
import com.yonge.cooleshow.biz.dal.support.PageUtil;
import com.yonge.cooleshow.biz.dal.vo.TeacherHomeVo;
import com.yonge.cooleshow.biz.dal.vo.TeacherStyleVideoVo;
import com.yonge.cooleshow.biz.dal.vo.TeacherVo;
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 io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
@Api(value = "教师表", tags = "教师表")
public class TeacherController extends BaseController {
    @Autowired
    private TeacherStyleVideoService styleVideoService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StudentStarService studentStarService;

    @ApiOperation(value = "老师风采-分页")
    @PostMapping("/stylePage")
    public HttpResponseResult<PageInfo<TeacherStyleVideoVo>> stylePage(@RequestBody TeacherStyleSearch query) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        query.setStudentId(user.getId());
        IPage<TeacherStyleVideoVo> pages = styleVideoService.stylePage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
    }

    @ApiOperation(value = "查询教师基本信息")
    @GetMapping("/queryTeacherHome")
    public HttpResponseResult<TeacherHomeVo> queryTeacherHome(@ApiParam(value = "老师ID", required = true) @RequestParam("userId") Long userId) {
        if (null == userId) {
            return failed("缺少老师ID");
        }
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        return teacherService.queryTeacherHome(user.getId(), userId);
    }

    @ApiOperation(value = "关注/取消关注")
    @GetMapping("/starOrUnStar")
    public HttpResponseResult<Boolean> starOrUnStar(@ApiParam(value = "老师ID", required = true) @RequestParam("userId") Long userId,
                                                    @ApiParam(value = "状态 0 取消关注 1 关注", required = true) @RequestParam("starStatus") YesOrNoEnum starStatus) {
        if (null == userId) {
            return failed("缺少老师ID");
        }
        if (null == starStatus) {
            return failed("缺少关注状态");
        }
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        return studentStarService.starOrUnStar(user.getId(), userId, starStatus);
    }


    @ApiOperation(value = "增加视频浏览量")
    @GetMapping("/addVideoBrowse")
    public HttpResponseResult<Boolean> addVideoBrowse(@ApiParam(value = "视频ID", required = true) @RequestParam("videoId") Long videoId) {
        if (null == videoId) {
            return failed("缺少videoId");
        }
        return styleVideoService.addVideoBrowse(videoId);
    }

    @ApiOperation(value = "增加主页浏览量")
    @GetMapping("/addHomeBrowse")
    public HttpResponseResult<Boolean> addHomeBrowse(@ApiParam(value = "老师ID", required = true) @RequestParam("userId") Long userId) {
        if (null == userId) {
            return failed("缺少userId");
        }
        return teacherService.addHomeBrowse(userId);
    }
}