package com.persagy.bdtp.adm.entity;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class D2mMessage {

	private String id;

	private String itemType; //object|relation|pipe

	private List<Object> addItems;

	private List<Object> modifyItems;

	private List<Object> removeItems;

	public D2mMessage(String itemType) {
		this.id = IdUtil.simpleUUID();
		this.itemType = itemType;
	}

	public void appendAddItem(Object item){
		if (addItems == null)
			addItems = new ArrayList<>();
		addItems.add(item);
	}

	public void appendModifyItem(Object item){
		if (modifyItems == null)
			modifyItems = new ArrayList<>();
		modifyItems.add(item);
	}

	public void appendRemoveItem(Object item){
		if (removeItems == null)
			removeItems = new ArrayList<>();
		removeItems.add(item);
	}

	@JsonIgnore
	public boolean isNotEmpty(){
		return CollUtil.isNotEmpty(addItems) || CollUtil.isNotEmpty(modifyItems) || CollUtil.isNotEmpty(removeItems);
	}

}
