package com.fdkankan.ucenter.controller.app;

import com.alibaba.fastjson.JSONObject;
import com.fdkankan.common.util.SecurityUtil;
import com.fdkankan.ucenter.annotation.VerifySign;
import com.fdkankan.ucenter.common.BaseController;
import com.fdkankan.ucenter.common.Result;
import com.fdkankan.ucenter.service.ISceneProService;
import com.fdkankan.ucenter.service.impl.AppSceneService;
import com.fdkankan.ucenter.service.impl.AppService;
import com.fdkankan.ucenter.vo.request.AppSceneParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ucenter/app/scene")
public class AppSceneController extends BaseController {

    @Autowired
    AppSceneService appSceneService;

    /**
     * 获取云端场景
     */
    @PostMapping("/getAppAllSceneByPage")
    @VerifySign
    public Result getAppAllSceneByPage(@RequestBody AppSceneParam param){
        if(param.getCameraType() == 4){
            param.setCameraType(1);
        }
        return Result.success( appSceneService.pageList(param));
    }

    /**
     * 获取场景计算状态
     */
    @PostMapping("/getSceneStatusByUnicode")
    @VerifySign
    public Result getSceneStatusByUnicode(@RequestBody JSONObject param){
        String appUserName = param.get("appUserName") == null ? null : param.getString("appUserName");
        String appPassword = param.get("appPassword") == null ? null : param.getString("appPassword");
        String unicode = param.get("unicode") == null ? null : param.getString("unicode");
        return Result.success(appSceneService.getSceneStatusByUnicode(appUserName,appPassword,unicode));
    }

    /**
     * 通知服务器音频上传成功
     * screencapMusic
     * originalFileName     音频文件在阿里云的地址Url
     * sceneNum             场景码
     */
    @PostMapping("/getScreencapVoice")
    @VerifySign
    public Result getScreencapVoice(@RequestBody JSONObject param) throws Exception {
        String screencapMusic = param.get("screencapMusic") == null ? null : param.getString("screencapMusic");
        String originalFileName = param.get("originalFileName") == null ? null : param.getString("originalFileName");
        String sceneNum = param.get("sceneNum") == null ? null : param.getString("sceneNum");
        appSceneService.getScreencapVoice(screencapMusic,originalFileName,sceneNum);
        return Result.success();
    }

    /**
     * 删除场景
     */
    @PostMapping("/deleteForCameraName")
    @VerifySign
    public Result deleteForCameraName(@RequestBody JSONObject param){
        Long cameraId = param.get("cameraId") == null ? null : param.getLong("cameraId");
        String sceneNum = param.get("sceneNum") == null ? null : param.getString("sceneNum");
        appSceneService.deleteForCameraName(cameraId,sceneNum,getUserId());
        return Result.success();
    }
}
