package cn.reghao.tnb.file.app.zdisk.controller;

import cn.reghao.jutil.jdk.web.result.Result;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.file.app.zdisk.model.dto.CreateFolder;
import cn.reghao.tnb.file.app.zdisk.model.dto.RenameFile;
import cn.reghao.tnb.file.app.zdisk.model.vo.FolderTree;
import cn.reghao.tnb.file.app.zdisk.service.DiskFolderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2025-09-01 10:16:46
 */
@Tag(name = "网盘文件夹接口")
@RestController
@RequestMapping("/api/disk/folder")
@AuthUser
public class DiskFolderController {
    private final DiskFolderService diskFolderService;

    public DiskFolderController(DiskFolderService diskFolderService) {
        this.diskFolderService = diskFolderService;
    }

    @Operation(summary = "当前文件夹下新建一个子文件夹", description = "N")
    @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
    public String createFolder(@RequestBody @Validated CreateFolder createFolder) {
        Result result = diskFolderService.createFolder(createFolder);
        return WebResult.result(result);
    }

    @Operation(summary = "重命名文件夹", description = "N")
    @PostMapping(value = "/rename", produces = MediaType.APPLICATION_JSON_VALUE)
    public String renameFolder(@RequestBody @Validated RenameFile renameFile) {
        return WebResult.successWithMsg("尚未实现");
    }

    @Operation(summary = "获取文件夹树, 返回的数据格式对应 elementui 的 el-tree", description = "N")
    @GetMapping(value = "/tree", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getFolderTree() {
        List<FolderTree> list = diskFolderService.getFolderTree();
        return WebResult.success(list);
    }
}
