package com.fdkankan.scene.factory.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fdkankan.common.constant.CommonStatus;
import com.fdkankan.common.constant.ErrorCode;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.scene.entity.SceneEditInfo;
import com.fdkankan.scene.entity.ScenePro;
import com.fdkankan.scene.service.ISceneEditInfoService;
import com.fdkankan.scene.service.IScenePlusExtService;
import com.fdkankan.scene.service.IScenePlusService;
import com.fdkankan.scene.service.ISceneProService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * <p>
 * </p>
 *
 * @author dengsixing
 * @since 2022/1/20
 **/
@Component
public class ScreenshotHandler implements ISaveUploadHandler {

    @Autowired
    private ISceneEditInfoService sceneEditInfoService;
    @Autowired
    private ISceneProService sceneProService;
    @Autowired
    IScenePlusService scenePlusService;
    @Autowired
    IScenePlusExtService scenePlusExtService;

    @Override
    public ResultData save(String num, String fileInfo) {

//        ScenePro scenePro = sceneProService.findBySceneNum(num);
//        if(Objects.isNull(scenePro))
//            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
//
//        JSONObject fileInfoJson = JSON.parseObject(fileInfo);
//        String initialPoint = fileInfoJson.getString("initialPoint");
//
//        // TODO: 2022/1/28旧代码中根据thumbBigImg.jpg生成thumbSmallImg.jpg，这里暂时不知道要不要，先留着
//
//        SceneEditInfo sceneEditInfoDb = sceneEditInfoService.getBySceneProId(scenePro.getId());
//        if(Objects.nonNull(sceneEditInfoDb)){
//            sceneEditInfoService.update(new LambdaUpdateWrapper<SceneEditInfo>()
//                    .setSql("version=version+" + 1)
//                    .set(SceneEditInfo::getInitialPoint, initialPoint)
//                    .set(SceneEditInfo::getThumbStatus, CommonStatus.YES.code())
//                    .eq(SceneEditInfo::getId, sceneEditInfoDb.getId()));
//        }else{
//            sceneEditInfoDb = new SceneEditInfo();
//            sceneEditInfoDb.setSceneProId(scenePro.getId());
//            sceneEditInfoDb.setInitialPoint(initialPoint);
//            sceneEditInfoDb.setThumbStatus(CommonStatus.YES.code());
//            sceneEditInfoService.save(sceneEditInfoDb);
//        }

        return ResultData.ok();
    }
}
