package org.springblade.file.pojo.dto;

import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 业务附件信息表 数据传输对象实体类
 *
 * @author BladeX
 * @since 2024-09-04
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Schema(description = "业务附件批量新增参数")
public class BusinessAttachmentBatchAddDTO implements Serializable {
	@Serial
	private static final long serialVersionUID = 1L;

	/**
	 * 业务id
	 */
	@NotNull(message = "业务id不能为空")
	@Schema(description = "业务id")
	private Long bizId;

	/**
	 * 明细列表
	 */
	@Schema(description = "明细列表")
	private List<@Valid BusinessAttachmentBatchAddDetailDTO> details;

	/**
	 *  是否先删除，默认 是
	 */
	@Schema(description = "是否先删除，默认 是")
	private boolean remove = true;

	public BusinessAttachmentBatchAddDTO(Long bizId) {
		this.bizId = bizId;
	}

	public BusinessAttachmentBatchAddDTO(Long bizId, String bizCode, Long attachmentId) {
		this.bizId = bizId;
		this.details = Lists.newArrayList(new BusinessAttachmentBatchAddDetailDTO(bizCode, attachmentId));
	}

	public BusinessAttachmentBatchAddDTO addDetail(BusinessAttachmentBatchAddDetailDTO detail) {
		if (this.details == null) {
			this.details = new ArrayList<>();
		}
		this.details.add(detail);
		return this;
	}

	public BusinessAttachmentBatchAddDTO addDetail(String bizCode, Long attachmentId) {
		return this.addDetail(new BusinessAttachmentBatchAddDetailDTO(bizCode, attachmentId));
	}

	public BusinessAttachmentBatchAddDTO addDetail(String bizCode, List<Long> attachmentIds) {
		return this.addDetail(new BusinessAttachmentBatchAddDetailDTO(bizCode, attachmentIds));
	}
}
