package com.fdkankan.scene.controller;

import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.scene.service.ISceneEditInfoService;
import com.fdkankan.scene.service.IScenePlusService;
import com.fdkankan.scene.service.ISceneService;
import com.fdkankan.scene.service.ISceneUpgradeToV4Service;
import com.fdkankan.scene.vo.CopySceneParamVO;
import com.fdkankan.scene.vo.MoveSceneParamVO;
import com.fdkankan.scene.vo.UnbindOrBindCameraParamVO;
import com.fdkankan.scene.vo.UpgradeToV4ParamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author dengsixing
 * @since 2022/5/20
 **/
@RestController
@RequestMapping("/service-v3/scene")
public class V3Controller extends BaseController {

    @Autowired
    private ISceneUpgradeToV4Service sceneUpgradeToV4Service;
    @Autowired
    private ISceneEditInfoService sceneEditInfoService;
    @Autowired
    private IScenePlusService scenePlusService;
    @Autowired
    private ISceneService sceneService;


    /**
     * <p>
     场景升级
     此接口用于V3\V4系统并存过渡期，场景升级v4做数据迁移用，待V3关闭可以删除
     * </p>
     * @author dengsixing
     * @date 2022/4/21
     * @return com.fdkankan.common.response.ResultData
     **/
    @PostMapping(value = "/upgradeToV4")
    public ResultData upgradeToV4(@RequestBody @Validated UpgradeToV4ParamVO param){
        ResultData resultData = sceneUpgradeToV4Service.upgradeToV4(param);
        return resultData;
    }

    /**
     * <p>
     场景升级进度查询
     此接口用于V3\V4系统并存过渡期，场景升级v4做数据迁移用，待V3关闭可以删除
     * </p>
     * @author dengsixing
     * @date 2022/4/21
     * @return com.fdkankan.common.response.ResultData
     **/
    @GetMapping(value = "/getUpgradeToV4Progress")
    public ResultData getUpgradeToV4Progress(@RequestParam(value = "num") String num){
        ResultData resultData = sceneUpgradeToV4Service.getUpgradeToV4Progress(num);
        return resultData;
    }

    /**
     * <p>
     查询场景scenejson
     此接口用于V3\V4系统并存过渡期，待V3关闭可以删除
     * </p>
     * @author dengsixing
     * @date 2022/4/21
     * @return com.fdkankan.common.response.ResultData
     **/
    @GetMapping(value = "/getSceneViewInfo")
    public ResultData getSceneViewInfo(@RequestParam(value = "num") String num){
        return sceneUpgradeToV4Service.getSceneViewInfo(num);
    }

    /**
     * <p>
            v3相机解绑和绑定，需要同步v4场景的userid
     * </p>
     * @author dengsixing
     * @date 2022/6/23
     * @return com.fdkankan.common.response.ResultData
     **/
    @PostMapping(value = "/updateScenePlusUserIdByCameraId")
    public ResultData updateScenePlusUserIdByCameraId(@RequestBody @Validated UnbindOrBindCameraParamVO param){
        return scenePlusService.updateScenePlusUserIdByCameraId(param.getCameraIdList(), param.getUserId());
    }

    /**
     * <p>
            场景迁移，修改相机id和用户id
     * </p>
     * @author dengsixing
     * @date 2022/6/23
     * @return com.fdkankan.common.response.ResultData
     **/
    @PostMapping(value = "/moveScene")
    public ResultData moveScene(
        @RequestBody @Validated MoveSceneParamVO param){
        return scenePlusService.moveScene(param.getNumList(), param.getCameraId(), param.getUserId());
    }

    /**
     * <p>
         场景拷贝
     * </p>
     * @author tianboguang
     * @date 2022/6/29
     * @return com.fdkankan.common.response.ResultData
     **/
    @PostMapping(value = "/copyScene")
    public ResultData copyScene(
            @RequestBody @Validated CopySceneParamVO param) throws Exception {
        sceneService.copyScene(param);
        return ResultData.ok();
    }


}
