package com.fdkankan.scene.controller;


import cn.hutool.core.util.StrUtil;
import com.fdkankan.common.constant.ErrorCode;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.common.user.SSOLoginHelper;
import com.fdkankan.common.user.SSOUser;
import com.fdkankan.common.util.JwtUtil;
import com.fdkankan.platform.api.feign.PlatformGoodsClient;
import com.fdkankan.platform.api.vo.Camera;
import com.fdkankan.scene.entity.SceneCooperation;
import com.fdkankan.scene.service.ISceneCooperationService;
import com.fdkankan.scene.vo.SceneCooperationParamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dengsixing
 * @since 2021-12-23
 */
@RestController
@RequestMapping("/api/scene/user/cooperation")
public class SceneCooperationController extends BaseController {

    @Autowired
    private SSOLoginHelper ssoLoginHelper;
    @Autowired
    private ISceneCooperationService sceneCooperationService;

    /**
     * 协作者根据场景码获取场景资源集合
     * @return
     */
    @RequestMapping(value = "/sceneResourceBySceneNum")
    public ResultData sceneResourceBySceneNum(@RequestBody SceneCooperationParamVO param) throws Exception{
        SSOUser ssoUser = ssoLoginHelper.loginCheck(getToken());

        if(StrUtil.isEmpty(param.getNum())){
            throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
        }

        // 解密获得username，用于和数据库进行对比
        String username = JwtUtil.getUsername(getToken());

        param.setUserId(ssoUser.getId());
        param.setUserName(username);

        return sceneCooperationService.sceneResourceBySceneNum(param);
    }

}

