package com.test.bijihoudaun.controller;

import com.test.bijihoudaun.annotation.RequireCaptcha;
import com.test.bijihoudaun.common.response.R;
import com.test.bijihoudaun.entity.TrashItemVo;
import com.test.bijihoudaun.service.TrashService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/trash")
@Tag(name = "回收站管理")
public class TrashController {

    @Autowired
    private TrashService trashService;

    @GetMapping
    @Operation(summary = "获取回收站列表")
    public R<List<TrashItemVo>> getTrashItems() {
        return R.success(trashService.getTrashItems());
    }

    @PostMapping("/restore/{type}/{id}")
    @PreAuthorize("hasRole('ADMIN')")
    @Operation(summary = "恢复项目")
    public R<Void> restoreItem(@PathVariable String type, @PathVariable String id) {
        trashService.restoreItem(id, type);
        return R.success();
    }

    @DeleteMapping("/permanently/{type}/{id}")
    @PreAuthorize("hasRole('ADMIN')")
    @RequireCaptcha("永久删除")
    @Operation(summary = "永久删除项目")
    public R<Void> permanentlyDeleteItem(@PathVariable String type, @PathVariable String id) {
        trashService.permanentlyDeleteItem(id, type);
        return R.success();
    }

    @DeleteMapping("/clean")
    @PreAuthorize("hasRole('ADMIN')")
    @RequireCaptcha("清空回收站")
    @Operation(summary = "清空回收站")
    public R<Void> cleanTrash() {
        trashService.cleanTrash();
        return R.success();
    }
}
