package org.dromara.system.controller.project;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.dto.projectfile.BusProjectFileQueryReq;
import org.dromara.system.domain.dto.projectfile.BusProjectFileUpdateReq;
import org.dromara.system.domain.vo.projectfile.BusProjectFileVo;
import org.dromara.system.service.IBusProjectFileService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目文件存储
 *
 * @author lilemy
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/projectFile")
public class BusProjectFileController extends BaseController {

    private final IBusProjectFileService busProjectFileService;

    /**
     * 查询项目文件存储列表
     */
    @SaCheckPermission("project:projectFile:list")
    @GetMapping("/list")
    public TableDataInfo<BusProjectFileVo> list(BusProjectFileQueryReq req, PageQuery pageQuery) {
        return busProjectFileService.queryPageList(req, pageQuery);
    }

    /**
     * 获取项目文件存储详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:projectFile:query")
    @GetMapping("/{id}")
    public R<BusProjectFileVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(busProjectFileService.queryById(id));
    }

    /**
     * 修改项目文件存储
     */
    @SaCheckPermission("project:projectFile:edit")
    @Log(title = "项目文件存储", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BusProjectFileUpdateReq req) {
        return toAjax(busProjectFileService.updateByBo(req));
    }

    /**
     * 删除项目文件存储
     *
     * @param ids 主键串
     */
    @SaCheckPermission("project:projectFile:remove")
    @Log(title = "项目文件存储", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busProjectFileService.deleteWithValidByIds(List.of(ids), true));
    }
}
