package cn.estsh.i3plus.pojo.mdm.bean.busi;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2021-03-29 17:37
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "MDM_DATA_SUBSCRIBE")
@ApiModel("数据订阅信息")
public class MdmDataSubscribe extends BaseBean {

    private static final long serialVersionUID = 8821827445193232389L;

    @Column(name = "MDM_CLASS_NAME")
    @ApiParam("主数据类名")
    private String mdmClassName;

    @Column(name = "MDM_NAME")
    @ApiParam("主数据名称")
    private String mdmName;


    @Column(name = "MDM_SUBSCRIBE")
    @ApiParam("订阅对象")
    private String mdmSubscribe;

    @Column(name = "MDM_SUBSCRIBE_TYPE")
    @ApiParam("订阅类型")
    private Integer mdmSubscribeType;

    @Column(name = "MDM_SUBSCRIBE_PERMISSIONS")
    @ApiParam("订阅权限")
    private String mdmSubscribePermissions;

    @Column(name = "MDM_SUBSCRIBE_FIELD")
    @ApiParam("订阅字段")
    @Lob
    private String mdmSubscribeField;

    @Transient
    @ApiParam("订阅字段保存List")
    private List<String> mdmSubscribeFields;




    @Column(name = "INTERNAL_APP_NUM")
    @ApiParam("内部订阅应用数量")
    private Integer internalAppNum;

    public long addInternalAppNum() {
        if (internalAppNum == null) {
            internalAppNum = 1;
        } else {
            internalAppNum++;
        }
        return internalAppNum;
    }

    @Column(name = "EXTERNAL_APP_NUM")
    @ApiParam("外部订阅应用数量")
    private Integer externalAppNum;

    public long addExternalAppNum() {
        if (externalAppNum == null) {
            externalAppNum = 1;
        } else {
            externalAppNum++;
        }
        return externalAppNum;
    }

    @Transient
    @ApiParam("内部订阅信息")
    private List<MdmDataSubscribeDetail> internalAppSubList;

    public List<MdmDataSubscribeDetail> getInternalAppSubList() {
        return internalAppSubList == null ? new ArrayList<>() : internalAppSubList;
    }

    public void addInternalApp(MdmDataSubscribeDetail detail) {
        if (internalAppSubList == null) {
            internalAppSubList = new ArrayList<>();
        }
        internalAppSubList.add(detail);
    }

    @Transient
    @ApiParam("外部订阅信息")
    private List<MdmDataSubscribeDetail> externalAppSubList;

    public List<MdmDataSubscribeDetail> getExternalAppSubList() {
        return externalAppSubList == null ? new ArrayList<>() : externalAppSubList;
    }

    public void addExternalApp(MdmDataSubscribeDetail detail) {
        if (externalAppSubList == null) {
            externalAppSubList = new ArrayList<>();
        }
        externalAppSubList.add(detail);
    }

}
