package cn.sikey.mcdisk.controller.app.wristwatch;

import cn.sikey.framework.common.pojo.CommonResult;
import cn.sikey.mcdisk.controller.app.wristwatch.vo.DeleteContentsReqVO;
import cn.sikey.mcdisk.controller.app.wristwatch.vo.GetFileUploadURLReqVO;
import cn.sikey.mcdisk.enums.RateLimit;
import cn.sikey.mcdisk.pojo.McdiskResult;
import cn.sikey.mcdisk.service.FamilyCloudService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: nelson
 * @Date: 2025/5/29
 * @Description: 家庭云
 */
@RestController
@RequestMapping("/mcdisk/wristwatch/familyCloud")
@Slf4j
public class FamilyCloudController {

    @Resource
    private FamilyCloudService familyCloudService;

    /**
     * 上传文件到家庭云
     *
     * @param getFileUploadURLReqVO 上传文件到家庭云
     * @param accessToken           accessToken
     * @return
     */
    @RateLimit(key = "getFileUploadURL", type = RateLimit.LimitType.GLOBAL)
    @PostMapping("/getFileUploadURL")
    public CommonResult getFileUploadURL(@RequestHeader(name = "accessToken") String accessToken, @Validated @RequestBody GetFileUploadURLReqVO getFileUploadURLReqVO) {
        McdiskResult mcdiskResult = familyCloudService.getFileUploadURL(getFileUploadURLReqVO, accessToken);
        return CommonResult.success(mcdiskResult.getData());
    }

    /**
     * 删除家庭云文件
     *
     * @param deleteContentsReqVO 家庭云文件
     * @param accessToken         accessToken
     * @return
     */
    @RateLimit(key = "deleteContents", type = RateLimit.LimitType.GLOBAL)
    @PostMapping("/deleteContents")
    public CommonResult deleteContents(@RequestHeader(name = "accessToken") String accessToken, @Validated @RequestBody DeleteContentsReqVO deleteContentsReqVO) {
        McdiskResult mcdiskResult = familyCloudService.deleteContents(deleteContentsReqVO, accessToken);
        return CommonResult.success(mcdiskResult.getData());
    }

}
