package com.huimv.video.video.controller;


import com.huimv.common.token.TokenSign;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.video.video.entity.Camera;
import com.huimv.video.video.entity.vo.CameraListVo;
import com.huimv.video.video.entity.vo.CameraListsVo;
import com.huimv.video.video.entity.vo.CameraVo;
import com.huimv.video.video.service.ICameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author astupidcoder
 * @since 2021-09-13
 */
@RestController
@RequestMapping("/camera")
public class CameraController {
    @Autowired
    private ICameraService cameraService;


    @PostMapping("/list")
    public Result list(@RequestBody CameraListVo cameraListVo) {
        return cameraService.listPage(cameraListVo);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Camera camera) {

        if (camera == null) {
            return new Result(ResultCode.FAIL, "添加失败");
        }


        return cameraService.add(camera);

    }

    @PostMapping("/update")
    public Result update(@RequestBody Camera camera) {
        return cameraService.updates(camera);

    }

    @GetMapping("/remove")
    public Result remove(@RequestParam(value = "ids") List<Integer> ids) {
        cameraService.removeByIds(ids);
        return new Result(ResultCode.SUCCESS, "删除成功");
    }

    @PostMapping("/getCameraDetails")
    private Result getCameraDetails(@RequestBody CameraListsVo cameraListsVo) {

        List list = cameraService.getCameraDetails(cameraListsVo);
        return new Result(ResultCode.SUCCESS, list);
    }

    //返回苹果手机看监控视频地址
//    @PostMapping("/getCameraDetails2")
//    private Result getCameraDetails2(@RequestBody CameraListsVo cameraListsVo){
//        //
//        List list =  cameraService.getCameraDetails2(cameraListsVo);
//        return new Result(ResultCode.SUCCESS,list);
//    }

    @GetMapping("/getCameraDetailsByRoomId")
    private Result getCameraDetailsByRoomId(@RequestParam(name = "roomId") Integer roomId) {

        CameraVo list = cameraService.getCameraDetailsByRoomId(roomId);
        return new Result(ResultCode.SUCCESS, list);
    }

    @GetMapping("/updateStatus")
    private Result updateStatus(@RequestParam(value = "id") Integer id) {

        return cameraService.updateStatus(id);
    }


    @RequestMapping("/getByAreaId")
    private Result getByAreaId(Integer areaId, HttpServletRequest request) {

        List list = cameraService.getByAreaId(areaId);
        return new Result(ResultCode.SUCCESS, list);
    }


    @GetMapping("/initCamera")
    private Result initCamera(@RequestParam(name = "farmId") Integer farmId, HttpServletRequest request) {
        Integer userId = TokenSign.getMemberIdByJwtToken(request);

        return cameraService.initCamera(farmId, userId);
    }


    @GetMapping("/listScreenCamera")
    private Result listScreenCamera(@RequestParam(name = "farmId") Integer farmId) {

        return cameraService.listScreenCamera(farmId);
    }

    @GetMapping("/screenCamera")
    private Result screenCamera(@RequestParam(name = "farmId") Integer farmId) {

        return cameraService.screenCamera(farmId);
    }

    @GetMapping("/saveCamera")
    private Result saveCamera(@RequestParam(name = "farmId") Integer farmId) {

        return cameraService.saveCamera(farmId);
    }


}
