package com.yingpaipay.business.controller.applet;

import com.yingpaipay.business.domain.bo.*;
import com.yingpaipay.business.domain.vo.*;
import com.yingpaipay.business.service.IDocumentService;
import com.yingpaipay.business.service.IFolderService;
import com.yingpaipay.business.service.IProjectService;
import com.yingpaipay.business.service.ITextInService;
import com.yingpaipay.system.domain.vo.FolderPermissionVo;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.service.ISysUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RestController
@RequestMapping("/applet/scan")
@RequiredArgsConstructor
public class AppletScanController extends BaseController {

    private final ITextInService textInService;
    private final IDocumentService documentService;
    private final IFolderService folderService;
    private final IProjectService projectService;
    private final ISysUserService userService;

    @PostMapping("/scan")
    public R<AppletScanVo> scan(@RequestBody AppletScanBo bo) {
        return R.ok(new AppletScanVo(textInService.wordToPdf(textInService.imageToWord(bo.getFile()))));
    }

    @GetMapping("/listToSubmit")
    public TableDataInfo<AppletDocumentScanSubmitVo> listToSubmit(AppletDocumentScanSubmitBo bo, PageQuery pageQuery) {
        return documentService.listToSubmit(bo, pageQuery);
    }

    @PostMapping("/uploadOnSubmit")
    public R<Void> uploadOnSubmit(@RequestBody AppletUploadOnSubmitBo bo) {
        return toAjax(documentService.uploadOnSubmit(bo));
    }

    @GetMapping("/listProject")
    public TableDataInfo<ProjectVo> listProject(ProjectBo bo, PageQuery pageQuery) {
        return projectService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/listFolder")
    public R<List<FolderListVo>> listFolder(@RequestParam("projectId") Long projectId) {
        return R.ok(folderService.selectList(projectId));
    }

    @Deprecated
    @GetMapping("/listFolderPermission")
    public R<FolderPermissionVo> listFolderPermission(@RequestParam("projectId") Long projectId) {
        return R.ok(userService.selectUserFolderPermissionByProjectId(projectId));
    }

    @Deprecated
    @PostMapping("/uploadNew")
    public R<Void> uploadNew(@RequestBody AppletUploadNewBo bo) {
        return toAjax(documentService.uploadNew(bo));
    }

    @PostMapping("/upload")
    public R<Void> upload(@RequestBody AppletUploadBo bo) {
        return toAjax(documentService.upload(bo));
    }

}
