package ink.wgink.module.form.controller.app.api.onlyoffice;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.form.pojo.vos.onlyoffice.OnlyOfficeSaveVO;
import ink.wgink.module.form.service.onlyoffice.IOnlyOfficeService;
import ink.wgink.pojo.result.ErrorResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: OnlyOfficeController
 * @Description: OnlyOffice
 * @Author: CodeFactory
 * @Date: 2022-06-24 15:06:48
 * @Version: 3.0
 **/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "OnlyOffice")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/only-office")
public class OnlyOfficeAppController extends DefaultBaseController {

    @Autowired
    private IOnlyOfficeService onlyOfficeService;

    @ApiOperation(value = "保存文件", notes = "保存文件接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileId", value = "文件ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("save-release/code/{formCode}/version/{formVersion}/uid/{uid}/file-id/{fileId}")
    @CheckRequestBodyAnnotation
    public Map<String, Object> save(@PathVariable("formCode") String formCode,
                                    @PathVariable("formVersion") Integer formVersion,
                                    @PathVariable("uid") String uid,
                                    @PathVariable("fileId") String fileId,
                                    @RequestBody OnlyOfficeSaveVO onlyOfficeSaveVO) {
        if(onlyOfficeSaveVO.getStatus() == 2) {
            onlyOfficeService.save(formCode, formVersion, uid, fileId, onlyOfficeSaveVO);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("error", 0);
        return result;
    }


}