package ink.wgink.module.form.controller.route.onlyoffice;

import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.form.service.onlyoffice.IOnlyOfficeService;
import ink.wgink.properties.onlyoffice.OnlyOfficeProperties;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName: OnlyOfficeRouteController
 * @Description: OnlyOffice
 * @Author: wanggeng
 * @Date: 2022/7/24 14:45
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "OnlyOffice")
@Controller
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/only-office")
public class OnlyOfficeRouteController {

    @Autowired
    private OnlyOfficeProperties onlyOfficeProperties;
    @Autowired
    private IOnlyOfficeService onlyOfficeService;

    @GetMapping("edit/code/{formCode}/version/{formVersion}/uid/{uid}/file-id/{fileId}")
    public ModelAndView edit(@PathVariable("formCode") String formCode,
                             @PathVariable("formVersion") Integer formVersion,
                             @PathVariable("uid") String uid,
                             @PathVariable("fileId") String fileId) {
        ModelAndView modelAndView = new ModelAndView("only-office/edit");
        modelAndView.addObject("fileId", fileId);
        modelAndView.addObject("server", onlyOfficeProperties.getServerUrl());
        modelAndView.addObject("config", onlyOfficeService.getConfig(formCode, formVersion, uid, fileId));
        return modelAndView;
    }


}
