package com.zxdmy.excite.admin.controller.cloud.recycle;


import cn.dev33.satoken.stp.StpUtil;
import com.zxdmy.excite.common.base.BaseController;
import com.zxdmy.excite.common.base.BaseResult;
import com.zxdmy.excite.common.entity.PageList;
import com.zxdmy.excite.framework.aop.AnnotationSaveReLog;
import com.zxdmy.excite.system.entity.req.space.ReqCloudFile;
import com.zxdmy.excite.system.entity.vo.space.CloudFileVo;
import com.zxdmy.excite.system.service.cloud.space.ICloudFileService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * <p>
 * 文件表 前端控制器
 * </p>
 *
 * @author ss
 * @since 2026-01-28
 */
@Controller
@AllArgsConstructor
@RequestMapping("/cloud/myRecycle")
public class CloudMyRecycleController extends BaseController {


    private ICloudFileService iCloudFileService;

    @RequestMapping("index")
    public String index() {
        return "cloud/recycle/index";
    }


    @GetMapping("/list")
    @ResponseBody
    public BaseResult getPageList(Integer page, Integer limit, ReqCloudFile data) {
        try {
            data.setCreatorId(StpUtil.getLoginIdAsInt());
            PageList<CloudFileVo> dataPage = iCloudFileService.queryByRecyclePage(page, limit, data);
            return success("获取数据成功", dataPage.getList(), (int) dataPage.getTotal());
        } catch (Exception e) {
            return error(500, "发生错误:" + e.getMessage());
        }
    }


    @PostMapping("/recover")
    @ResponseBody
    public BaseResult recover(String id) {
        try {
            int result = iCloudFileService.recover(id);
            if (result == 1) {
                return success(200, "恢复成功！");
            }else{
                return error("恢复失败！");
            }
        } catch (Exception e) {
            return error("发生错误:" + e.getMessage());
        }
    }

    @PostMapping("/foreverDelete")
    @ResponseBody
    @AnnotationSaveReLog
    public BaseResult foreverDelete(String id) {
        try {
            int result = iCloudFileService.deleteById(id);
            if (result == 1) {
                return success(200, "删除成功！");
            }else{
                return error("删除失败！");
            }
        } catch (Exception e) {
            return error("发生错误:" + e.getMessage());
        }
    }
}
