package com.sptg.gateway.controller.videoCloud;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.video.cloud.api.constant.VideoCloudSecurityToken;
import com.sptg.video.cloud.api.dto.VCApiLogDto;
import com.sptg.video.cloud.api.entity.VCApiLog;
import com.sptg.video.cloud.api.feigns.VCApiLogFeign;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zwx
 * @create 2020/10/18 23:29
 * 视频云接口日志控制器
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/videoCloud/apiLog")
public class VCApiLogController {

    private final VCApiLogFeign vcApiLogFeign;

    /**
     * 功能描述: 视频云接口日志界面
     * @return ModelAndView
     */
    @GetMapping(value = "/manage/index")
    @Security(token = VideoCloudSecurityToken.VIDEO_CLOUD_APILOG_INFO_MANAGE, format = DataFormatEnum.VIEW)
    public ModelAndView apiLogManage(){
        return new ModelAndView("videoCloud/vc-api-log-manage");
    }

    /**
     * 功能描述: 视频云接口日志分页查询接口日志列表
     *
     * @param vcApiLogDto      查询条件
     * @param pageBean 分页条件
     * @return ResultBean<Page>
     */
    @GetMapping(value = "/pagingQuery")
    @Security(token = VideoCloudSecurityToken.VIDEO_CLOUD_APILOG_INFO_MANAGE, format = DataFormatEnum.JSON)
    public ResultBean<Page<VCApiLog>> pagingQuery(VCApiLogDto vcApiLogDto, PageBean<VCApiLog, VCApiLogDto> pageBean) {
        pageBean.setDto(vcApiLogDto);
        return this.vcApiLogFeign.pagingQuery(pageBean);
    }

    /**
     * 功能描述: 视频云设备详情界面
     * @return ModelAndView
     */
    @GetMapping(value = "/detail/{id}")
    @Security(token = VideoCloudSecurityToken.VIDEO_CLOUD_APILOG_INFO_MANAGE, format = DataFormatEnum.VIEW)
    public ModelAndView detail(@PathVariable(value = "id") Long id){
        VCApiLog vcApiLog = this.vcApiLogFeign.findById(id);
        if (vcApiLog == null){
            return new ModelAndView("common/404");
        }
        ModelAndView modelAndView = new ModelAndView("videoCloud/vc-api-log-detail");
        modelAndView.addObject("vcApiLog",vcApiLog);
        return modelAndView;
    }
}
