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

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.jutil.jdk.web.result.Result;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.auth.api.dto.AccountAvatar;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.file.app.zdisk.model.dto.ShareCreate;
import cn.reghao.tnb.file.app.zdisk.model.vo.DiskShareInfo;
import cn.reghao.tnb.file.app.zdisk.service.DiskShareService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2025-09-05 17:03:15
 */
@Tag(name = "网盘分享接口")
@RestController
@RequestMapping("/api/disk/share")
@AuthUser
public class DiskShareController {
    private final DiskShareService diskShareService;

    public DiskShareController(DiskShareService diskShareService) {
        this.diskShareService = diskShareService;
    }

    @Operation(summary = "创建分享", description = "N")
    @PostMapping("/create")
    public String createShare(@RequestBody @Validated ShareCreate shareCreate) {
        Result result = diskShareService.createShare(shareCreate);
        return WebResult.result(result);
    }

    @Operation(summary = "删除分享", description = "N")
    @PostMapping("/delete/{shareId}")
    public String deleteShare(@PathVariable("shareId") long shareId) {
        Result result = diskShareService.deleteShare(shareId);
        return WebResult.result(result);
    }

    @Operation(summary = "获取分享列表", description = "N")
    @GetMapping("/list")
    public String getShareList(@RequestParam("pn") int pageNumber) {
        PageList<DiskShareInfo> pageList = diskShareService.getShareList(pageNumber);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取被分享用户列表", description = "N")
    @GetMapping("/user_list")
    public String getShareToList(@RequestParam("shareId") long shareId) {
        List<AccountAvatar> list = diskShareService.getShareToList(shareId);
        return WebResult.success(list);
    }
}
