package com.fdkankan.scene.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.common.util.PageInfoUtils;
import com.fdkankan.scene.entity.SceneCooperation;
import com.fdkankan.scene.service.IFolderService;
import com.fdkankan.scene.service.ISceneCooperationService;
import com.fdkankan.scene.vo.SceneCooperationParamVO;
import com.fdkankan.scene.vo.SceneParamVO;
import java.util.List;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

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

    /**
     * 协作者根据场景码获取场景资源集合
     * @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.PARAM_REQUIRED);
        }

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

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

        return sceneCooperationService.sceneResourceBySceneNum(param);
    }

    /**
     * 协作的场景--文件夹形式
     * @return
     */
    @RequestMapping(value = "/cooperationSceneListNew", method = RequestMethod.POST)
//    @ApiImplicitParams({
//        @ApiImplicitParam(name = "pageNum", value = "分页", dataType = "number"),
//        @ApiImplicitParam(name = "sceneSource", value = "1表示八目，2双目", dataType = "number"),
//        @ApiImplicitParam(name = "sceneType", value = "场景类型,0表示其他，1表示文博，2表示地产，3表示电商，4表示餐饮，5表示家居", dataType = "number"),
//        @ApiImplicitParam(name = "folderType", value = "文件夹类型：0场景，1协作场景", dataType = "String"),
//        @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String"),
//        @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String"),
//        @ApiImplicitParam(name = "pageSize", value = "每页大小", dataType = "number")})
    public Page cooperationSceneListNew(@RequestBody SceneParamVO param) throws Exception{
        Long userId = this.getUserId();
        param.setUserId(userId);
        return sceneCooperationService.cooperationSceneListNew(param);
    }


    @PostMapping("/test")
    public Page test(int pageNum, int pageSize){

        Page<SceneCooperation> page = new Page<>(pageNum, pageSize);
        List<SceneCooperation> list = sceneCooperationService.list();
        Page<SceneCooperation> sceneCooperationPage = PageInfoUtils.list2PageInfo(list, 1, 6);
        return sceneCooperationPage;

    }

}

