package com.fdkankan.ucenter.controller;

import com.dtflys.forest.annotation.Post;
import com.fdkankan.common.util.JwtUtil;
import com.fdkankan.ucenter.common.BaseController;
import com.fdkankan.ucenter.common.Result;
import com.fdkankan.ucenter.entity.SceneCooperation;
import com.fdkankan.ucenter.service.ISceneCooperationService;
import com.fdkankan.ucenter.vo.request.SceneCooperationParam;
import com.fdkankan.ucenter.vo.request.SceneParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ucenter/user/scene/cooperation")
public class SceneCooperationController extends BaseController {

    @Autowired
    ISceneCooperationService sceneCooperationService;

    @PostMapping("/sceneResourceList")
    public Result sceneResourceList(@RequestBody SceneCooperationParam param){
        return Result.success( sceneCooperationService.sceneResourceList(param));
    }

    @PostMapping("/cooperationSceneListNew")
    public Result cooperationSceneListNew(@RequestBody SceneParam param){
        return Result.success(sceneCooperationService.cooperationSceneListNew(param,getUserName()));
    }

    @PostMapping("/cooperationSceneList")
    public Result cooperationSceneList(@RequestBody SceneParam param){
        return Result.success(sceneCooperationService.cooperationSceneListNew(param,getUserName()));
    }

    @PostMapping("/onlyCooperationSceneList")
    public Result onlyCooperationSceneList(@RequestBody SceneParam param){
        return Result.success(sceneCooperationService.cooperationSceneListNew(param,getUserName()));
    }

    /**
     * 添加协作场景
     * userName         用户账号
     * sceneNum         场景码
     * resourceIds      场景资源id集合，逗号隔开
     */
    @PostMapping("/save")
    public Result save(@RequestBody SceneCooperationParam param){
        if(StringUtils.isNotBlank(getLang())){
            param.setLang(getLang());
        }
        sceneCooperationService.saveCooperation(param,getUserName());
        return Result.success();
    }

    @PostMapping("/saveBatch")
    public Result saveBatch(@RequestBody SceneCooperationParam param){
        if(StringUtils.isNotBlank(getLang())){
            param.setLang(getLang());
        }
        param.setTimeZone(getTimeZone());
        return Result.success(sceneCooperationService.saveBatchCooperation(param,getUserName()));
    }

    @PostMapping("/saveCamera")
    public Result saveCamera(@RequestBody SceneCooperationParam param){
        if(StringUtils.isNotBlank(getLang())){
            param.setLang(getLang());
        }
        param.setTimeZone(getTimeZone());
        return Result.success(sceneCooperationService.saveCamera(param,getUserName()));
    }



    /**
     * 取消协作场景
     * sceneNum         场景码
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody SceneCooperationParam param){
        sceneCooperationService.deleteCooperation(param,getUserName());
        return Result.success();
    }

    /**
     * 场景归属者根据场景码获取场景资源集合
     * sceneNum         场景编码
     */
    @PostMapping(value = "/findSceneResource")
    public Result findSceneResource(@RequestBody SceneCooperationParam param) throws Exception{
        return Result.success(sceneCooperationService.getResourceByNum(param.getSceneNum()));
    }
}
