package com.backendsys.modules.upload.controller;

import com.backendsys.modules.common.aspect.SysLog;
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.upload.entity.SysFile;
import com.backendsys.modules.upload.entity.SysFileCategory;
import com.backendsys.modules.upload.service.SysFileCategoryService;
import com.backendsys.modules.upload.service.SysFileService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Validated
@RestController
@Tag(name = "文件分类管理")
public class SysFileCategoryController {

    @Autowired
    private SysFileCategoryService sysFileCategoryService;

    /** 没必要 */
//    @Operation(summary = "获取文件分类列表 (全权限)")
//    @GetMapping("/api/upload/getUploadFileCategoryAllList")
//    public Result getUploadFileCategoryAllList(@Validated SysFileCategory sysFileCategory) {
//        return Result.success().put("data", sysFileCategoryService.selectUploadFileCategoryList(sysFileCategory));
//    }

    @Operation(summary = "获取文件分类列表 (我的)")
    @PreAuthorize("@sr.hasPermission('1.1.2')")
    @GetMapping("/api/upload/getUploadFileCategoryList")
    public Result getUploadFileCategoryList(@Validated SysFileCategory sysFileCategory) {
        sysFileCategory.setUser_id(SecurityUtil.getUserId());
        return Result.success().put("data", sysFileCategoryService.selectUploadFileCategoryList(sysFileCategory));
    }

    @SysLog("创建文件分类")
    @Operation(summary = "创建文件分类")
    @PreAuthorize("@sr.hasPermission('1.1.3')")
    @PostMapping("/api/upload/createFileCategory")
    public Result createFileCategory(@Validated(SysFileCategory.Create.class) @RequestBody SysFileCategory sysFileCategory) {
        sysFileCategory.setUser_id(SecurityUtil.getUserId());
        return Result.success().put("data", sysFileCategoryService.insertFileCategory(sysFileCategory));
    }

    @SysLog("编辑文件分类")
    @Operation(summary = "编辑文件分类")
    @PreAuthorize("@sr.hasPermission('1.1.4')")
    @PutMapping("/api/upload/updateFileCategory")
    public Result updateFileCategory(@Validated(SysFileCategory.Update.class) @RequestBody SysFileCategory sysFileCategory) {
        sysFileCategory.setUser_id(SecurityUtil.getUserId());
        return Result.success().put("data", sysFileCategoryService.updateFileCategory(sysFileCategory));
    }

    // 包含 增、删、改 权限
    @SysLog("编辑文件分类(批量)")
    @Operation(summary = "编辑文件分类(批量)")
    @PutMapping("/api/upload/updateFileCategoryBatch")
    public Result updateFileCategoryBatch(@Validated(SysFileCategory.UpdateBatch.class) @RequestBody SysFileCategory sysFileCategory) {
        return Result.success().put("data", sysFileCategoryService.updateFileCategoryBatch(sysFileCategory.getList()));
    }

    @SysLog("删除文件分类")
    @Operation(summary = "删除文件分类")
    @PreAuthorize("@sr.hasPermission('1.1.6')")
    @DeleteMapping("/api/upload/deleteFileCategory")
    public Result deleteFileCategory(@Validated(SysFileCategory.Delete.class) @RequestBody SysFileCategory sysFileCategory) {
        sysFileCategory.setUser_id(SecurityUtil.getUserId());
        return Result.success().put("data", sysFileCategoryService.deleteFileCategory(sysFileCategory));
    }

}
