package com.fdkankan.scene.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.response.PageInfo;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.scene.service.IUserSceneService;
import com.fdkankan.scene.vo.SceneDownloadParamVO;
import com.fdkankan.scene.vo.SceneParamVO;
import com.fdkankan.scene.vo.SceneVO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

/**
 * 个人中心-我的场景
 */
@Log4j2
@RestController
@RequestMapping("/service/scene/user/scene")
public class UserSceneController extends BaseController {

    @Autowired
    private IUserSceneService userSceneService;
    /**
     * 获取用户场景记录
     * pageNum          分页
     * searchKey        搜索条件
     * pageSize         每页大小
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Page<SceneVO> getScenes(@RequestBody SceneParamVO param) throws Exception {
        return userSceneService.getScenes(getToken(), param);

    }

    /**
     * 获取我的场景和协作场景数量
     * @return
     */
    @PostMapping(value = "/findSceneNumber")
    public ResultData findSceneNumber() throws Exception{
        return userSceneService.findSceneNumber(getToken());
    }

    /**
     * 获取用户场景记录
     * @param param
     * @return
     */
    @RequestMapping(value = "/newList", method = RequestMethod.POST)
    public ResultData<PageInfo<SceneVO>> getNewScenes(@RequestBody SceneParamVO param) throws Exception {
        param.setUserId(this.getUserId());
        return userSceneService.getNewScenes( param);
    }

    /**
     * 校验该场景有无下载资格
     * @param param
     * @return
     */
    @RequestMapping(value = "/checkDownload", method = RequestMethod.POST)
    public ResultData checkDownload(@RequestBody @Validated SceneDownloadParamVO param) throws Exception{
        return userSceneService.checkDownload(this.getUserId(), param);
    }

    /**
     * 场景下载
     * @param param
     * @return
     */
    @PostMapping(value = "/downloadScene")
    public ResultData downloadScene(@RequestBody @Validated SceneDownloadParamVO param) throws Exception{
        return userSceneService.downloadScene(this.getUserId(), param);
    }

    /**
     * 获取下载进度
     * @param param
     * @return
     */
    @RequestMapping(value = "/downloadProcess", method = RequestMethod.POST)
    public ResultData downloadProcess(@RequestBody @Validated SceneDownloadParamVO param) throws Exception{
        return userSceneService.getSceneDownloadProcess(this.getUserId(), param);
    }





}
