package com.younike.server.controller;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.SecurityUtils;
import com.younike.framework.config.AnonymousAccess;
import com.younike.framework.config.ServerAccess;
import com.younike.system.domain.Video;
import com.younike.system.param.VideoParam;
import com.younike.system.domain.vo.VideoVo;
import com.younike.system.service.IVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

    /**
     * 【服务人员】Controller
     *
     * @author elev
     * @date 2022-04-13
     */
    @Api("【请填写功能名称】接口")
    @RestController
    @RequestMapping("/server/video")
    public class ServerVideoController extends BaseController {
        @Autowired
        private IVideoService videoService;

        /**
         * 查询【请填写功能名称】列表
         */
        @ServerAccess
        @GetMapping("/list")
        public Object list(VideoParam video) {
            if(ObjectUtils.isEmpty(video) || video.getServerId() == null){
                return AjaxResult.error("参数错误");
            }
            startPage();
            List<VideoVo> list = videoService.getVideoList(video);
            return getDataTable(list);
        }



        /**
         * 获取【请填写功能名称】详细信息
         */
        @ServerAccess
        @GetMapping(value = "/{videoId}")
        public AjaxResult getInfo(@PathVariable("videoId") Long videoId) {
            return AjaxResult.success(videoService.getInfo(videoId));
        }

        /**
         * 新增【请填写功能名称】
         */
        @ServerAccess
        @Log(title = "【服务人员：添加视频】", businessType = BusinessType.INSERT)
        @PostMapping
        public AjaxResult add(@RequestBody Video video) {
            //校验数据
            if(ObjectUtils.isEmpty(video) || ObjectUtils.isEmpty(video.getVideoUrl() )||
                    ObjectUtils.isEmpty(video.getVideoFaceUrl()) ||
                    video.getVideoCategoryId()==null ||
                    ObjectUtils.isEmpty(video.getVideoDesc())||
                    video.getServerId()==null
                    ){
                return AjaxResult.error("参数错误");
            }
            return  toAjax(videoService.serverInsertVideo(video));
        }

        /**
         * 修改【请填写功能名称】
         */
        @ServerAccess
        @Log(title = "【视频数据】", businessType = BusinessType.UPDATE)
        @PutMapping
        public AjaxResult edit(@RequestBody Video video) {
            return toAjax(videoService.serverUpdateVideo(video));
        }


        /**
         * 删除视频
         */
        @ServerAccess
        @Log(title = "删除视频", businessType = BusinessType.DELETE)
        @DeleteMapping("/{videoId}")
        public AjaxResult remove(@PathVariable Long videoId ) {
            return toAjax(videoService.remove(videoId));
        }
    }
