package com.yonge.cooleshow.admin.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.req.AuthOperaReq;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import com.yonge.toolset.mybatis.support.PageUtil;

import com.yonge.toolset.base.page.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


import com.yonge.cooleshow.biz.dal.vo.TeacherStyleVideoVo;
import com.yonge.cooleshow.biz.dal.dto.search.TeacherStyleVideoSearch;
import com.yonge.cooleshow.biz.dal.service.TeacherStyleVideoService;

import javax.validation.Valid;

@RestController
@RequestMapping("/teacherStyleVideo")
@Api(value = "教师风采视频表", tags = "教师风采视频表")
public class TeacherStyleVideoController extends BaseController {
    @Autowired
    private TeacherStyleVideoService teacherStyleVideoService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    /**
     * 查询单条
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情", notes = "传入id")
    public HttpResponseResult<TeacherStyleVideoVo> detail(@PathVariable("id") Long id) {
        return succeed(teacherStyleVideoService.detail(id));
    }

    /**
     * 查询分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "查询分页", notes = "传入teacherStyleVideoSearch")
    public HttpResponseResult<PageInfo<TeacherStyleVideoVo>> page(@RequestBody TeacherStyleVideoSearch query) {
        //后端审核只查询非入驻审核视频
        query.setEntryFlag(YesOrNoEnum.NO);

        IPage<TeacherStyleVideoVo> pages = teacherStyleVideoService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
    }


    @PostMapping("/doAuth")
    @ApiOperation(value = "审核", notes = "传入authOperaDto")
    @PreAuthorize("@pcs.hasPermissions('teacherStyleVideo/doAuth')")
    public HttpResponseResult<Boolean> doAuth(@Valid @RequestBody AuthOperaReq authOperaReq) throws Exception {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        return succeed(teacherStyleVideoService.doAuth(authOperaReq, sysUser));
    }
}