package com.yingpaipay.business.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yingpaipay.business.domain.bo.FolderBo;
import com.yingpaipay.business.domain.bo.ProjectOnDocumentBo;
import com.yingpaipay.business.domain.vo.FolderListVo;
import com.yingpaipay.business.domain.vo.FolderVo;
import com.yingpaipay.business.domain.vo.ProjectOnDocumentVo;
import com.yingpaipay.business.service.IProjectService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.web.core.BaseController;
import com.yingpaipay.business.service.IFolderService;

import java.util.List;

/**
 * 文件夹管理
 *
 * @author Huanyi
 * @date 2025-12-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/document/folder")
public class FolderController extends BaseController {

    private final IFolderService folderService;
    private final IProjectService projectService;

    @SaCheckPermission("document:folder:list")
    @GetMapping("/listProject")
    public TableDataInfo<ProjectOnDocumentVo> listProject(ProjectOnDocumentBo bo, PageQuery pageQuery) {
        return projectService.listOnDocument(bo, pageQuery);
    }


    @SaCheckPermission("document:folder:list")
    @GetMapping("/list")
    public R<List<FolderListVo>> list(Long projectId) {
        return R.ok(folderService.selectList(projectId));
    }

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

    @SaCheckPermission("document:folder:add")
    @Log(title = "文件夹管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FolderBo bo) {
        return toAjax(folderService.insertByBo(bo));
    }

    @SaCheckPermission("document:folder:remove")
    @Log(title = "文件夹管理", businessType = BusinessType.DELETE)
    @RepeatSubmit()
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "不能为空") @PathVariable Long[] ids) {
        return toAjax(folderService.deleteWithValidIds(List.of(ids), true));
    }

    @SaCheckPermission("document:folder:edit")
    @Log(title = "文件夹管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FolderBo bo) {
        return toAjax(folderService.updateByBo(bo));
    }

    @SaCheckPermission("document:folder:query")
    @GetMapping("/{id}")
    public R<FolderVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(folderService.queryById(id));
    }

}
