package com.jiayue.ipfcst.common.data.entity;

import com.jiayue.ipfcst.common.data.constant.enums.TunnelType;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 通道信息的基类，用于与数据库交互传递信息的实体
 *
 * @author 修唯xiuwei
 * @version 3.0
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTunnelInfo<T> implements Serializable {

    /**
     * 通道的id  使用String的UUID 或雪花值 方便后期的通道联合查询
     */
    @Id
    @GenericGenerator(name = "custom-uuid", strategy = "com.jiayue.ipfcst.common.data.entity.id.CustomUUIDGenerator")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "custom-uuid")
    @Column(length = 64)
    protected String id;
    /**
     * 通道的名称
     */
    @Column(length = 100)
    protected String tunnelName;

    /**
     * 通道的类型，冗余字段
     */
    @Transient
    protected TunnelType tunnelType;

    /**
     * 数据刷新时间间隔 单位s 秒
     */
    @Column
    protected Integer refreshInterval = 5;

    /**
     * 通道是否启用
     */
    @Column
    protected Boolean isEnable = true;


    /**
     * 场站标识
     */
    @Column
    private String stationCode;


    /**
     * 通道中的点位
     */
    @JoinColumn(name = "tunnelId", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT), updatable = false)
    @OneToMany(fetch = FetchType.EAGER)
    List<T> dataPoints;


}
