package com.hotwj.platform.noticeManagerment.fileTypeConfig.controller;

import com.hotwj.platform.noticeManagerment.fileTypeConfig.domain.bo.HotFileTypeConfigBo;
import com.hotwj.platform.noticeManagerment.fileTypeConfig.domain.vo.HotFileTypeConfigVo;
import com.hotwj.platform.noticeManagerment.fileTypeConfig.service.IHotFileTypeConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
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.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件类型配置
 *
 * @author shihongwei
 * @date 2026-03-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/noticeManagerment/fileTypeConfig")
@Tag(name = "文件类型配置", description = "文件类型配置管理")
public class HotFileTypeConfigController extends BaseController {

    private final IHotFileTypeConfigService hotFileTypeConfigService;

    /**
     * 查询文件类型配置列表
     */
    //@SaCheckPermission("noticeManagerment:fileTypeConfig:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询文件类型配置列表")
    public TableDataInfo<HotFileTypeConfigVo> list(HotFileTypeConfigBo bo, PageQuery pageQuery) {
        return hotFileTypeConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文件类型配置列表
     */
    //@SaCheckPermission("noticeManagerment:fileTypeConfig:export")
    @Log(title = "文件类型配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出文件类型配置列表")
    public void export(HotFileTypeConfigBo bo, HttpServletResponse response) {
        List<HotFileTypeConfigVo> list = hotFileTypeConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "文件类型配置", HotFileTypeConfigVo.class, response);
    }

    /**
     * 获取文件类型配置详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("noticeManagerment:fileTypeConfig:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取文件类型配置详细信息")
    public R<HotFileTypeConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                          @Parameter(name = "id", description = "主键", required = true, example = "1")
                                          @PathVariable Long id) {
        return R.ok(hotFileTypeConfigService.queryById(id));
    }

    /**
     * 新增文件类型配置
     */
    //@SaCheckPermission("noticeManagerment:fileTypeConfig:add")
    @Log(title = "文件类型配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增文件类型配置")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotFileTypeConfigBo bo) {
        return toAjax(hotFileTypeConfigService.insertByBo(bo));
    }

    /**
     * 修改文件类型配置
     */
    //@SaCheckPermission("noticeManagerment:fileTypeConfig:edit")
    @Log(title = "文件类型配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改文件类型配置")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotFileTypeConfigBo bo) {
        return toAjax(hotFileTypeConfigService.updateByBo(bo));
    }

    /**
     * 删除文件类型配置
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("noticeManagerment:fileTypeConfig:remove")
    @Log(title = "文件类型配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除文件类型配置")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotFileTypeConfigService.deleteWithValidByIds(List.of(ids), true));
    }

    //@SaCheckPermission("noticeManagerment:fileTypeConfig:add")
    @Log(title = "文件类型配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/useDefault")
    @Operation(summary = "采用默认配置")
    public R<Void> useDefault() {
        return toAjax(hotFileTypeConfigService.useDefault());
    }
}
