package org.springblade.file.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.file.pojo.dto.BusinessAttachmentAddDTO;
import org.springblade.file.pojo.dto.BusinessAttachmentBatchAddDTO;
import org.springblade.file.pojo.dto.BusinessAttachmentQueryDTO;
import org.springblade.file.pojo.vo.BusinessAttachmentVO;
import org.springblade.file.service.IBusinessAttachmentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业务附件信息表 控制器
 *
 * @author BladeX
 * @since 2024-09-04
 */
@Valid
@RestController
@AllArgsConstructor
@RequestMapping("businessAttachment")
@Tag(name = "业务附件信息表", description = "业务附件信息表接口")
public class BusinessAttachmentController {

	private final IBusinessAttachmentService businessAttachmentService;

	/**
	 * 业务附件信息表 新增
	 */
	@PostMapping("/batchSave")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "批量新增", description  = "批量新增")
	public R batchSave(@Validated @RequestBody List<BusinessAttachmentAddDTO> params) {
		return R.status(businessAttachmentService.saveAndRemove(params, null));
	}

	/**
	 * 业务附件信息表 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "新增", description  = "新增")
	public R save(@Validated @RequestBody BusinessAttachmentBatchAddDTO param) {
		return R.status(businessAttachmentService.saveAndRemove(param));
	}

	/**
	 * 业务附件信息表 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "逻辑删除", description  = "传入bizId")
	public R remove(@Parameter(description = "bizId", required = true) @RequestParam Long bizId) {
		return R.status(businessAttachmentService.removeByBizIds(List.of(bizId)));
	}

	/**
	 * 查询业务附件信息列表
	 */
	@PostMapping("/queryList")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "查询业务附件信息列表", description  = "查询业务附件信息列表")
	public R<List<BusinessAttachmentVO>> queryList(@Validated @RequestBody BusinessAttachmentQueryDTO param) {
		return R.data(businessAttachmentService.queryList(param));
	}

}
