package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.IMonitoringService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * 监控 控制器
 * @author weiximei
 */
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "监控 控制器", description = "监控相关的数据")
public class MonitoringController extends BaseController {

    @Autowired
    private IMonitoringService iMonitoringService;

    @ApiOperation(value = "获取监控列表数据",notes = "根据小区ID获取")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "Integer",name = "communityId",value = "小区ID"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageNo",value = "第几页"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageSize",value = "一页多少行")
    })
    @RequestMapping(value = "/monitoring/{communityId}",method = RequestMethod.GET)
    public ResponseBean getList(@PathVariable("communityId") Integer communityId,
                                @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        ResponseBean response = new ResponseBean();
        if (!check(communityId)) {
            response.addError("小区不存在");
            return response;
        }

        response = iMonitoringService.getByCommunityId(communityId,pageNo,pageSize);
        return response;
    }


    @ApiOperation(value = "获取监控列表token",notes = "根据小区ID获取")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "Integer",name = "communityId",value = "小区ID"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageNo",value = "第几页"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageSize",value = "一页多少行")
    })
    @RequestMapping(value = "/monitoring/token/{communityId}",method = RequestMethod.GET)
    public ResponseBean getMonitoringToken(@PathVariable("communityId") Integer communityId,
                                @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize",defaultValue = "100") Integer pageSize){
        ResponseBean response = new ResponseBean();
        if (!check(communityId)) {
            response.addError("小区不存在");
            return response;
        }

        response = iMonitoringService.getMonitoringToken(communityId,pageNo,pageSize);
        return response;
    }

    @ApiOperation(value = "获取监控列表数据 HLS",notes = "根据小区ID获取")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "Integer",name = "communityId",value = "小区ID"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageNo",value = "第几页"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageSize",value = "一页多少行")
    })
    @RequestMapping(value = "/monitoring/hls/{communityId}",method = RequestMethod.GET)
    public ResponseBean getListHLS(@PathVariable("communityId") Integer communityId,
                                   @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                   @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize) {

        ResponseBean responseBean = new ResponseBean();
        responseBean = iMonitoringService.getHlsByCommunityId(communityId, pageNo, pageSize);
        return responseBean;
    }


    @ApiOperation(value = "获取门口机视频地址",notes = "获取门口机视频地址")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
    })
    @RequestMapping(value = "/monitoring/intercom",method = RequestMethod.GET)
    public ResponseBean getIntercomHLS(HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iMonitoringService.getIntercomHLS(userElement);
        return responseBean;
    }

}
