package com.bytesw.bytebot.model;

import com.bytesw.bytebot.model.converters.CalendarExceptionTypeConverter;
import com.bytesw.bytebot.model.converters.FrequencyTypeConverter;
import com.bytesw.bytebot.model.enums.CalendarExceptionType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.envers.Audited;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigInteger;

@Audited
@Entity
@Inheritance(
        strategy = InheritanceType.SINGLE_TABLE
)
@DiscriminatorColumn(name="CALE_EXC_FRECU", discriminatorType = DiscriminatorType.STRING)
@Table(name = "AVB_CALENDAR_EXCEPTION")
@Getter
@Setter
@EqualsAndHashCode
@ToString(exclude = "id")
public abstract class CalendarException implements Serializable {

    @Id
    @Column(name = "CALE_EXC_ID")
    @SequenceGenerator(name = "AVB_CALENDAR_EXCEPTION_GENERATOR", sequenceName = "AVB_CALENDAR_EXCEPTION_SEQ", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AVB_CALENDAR_EXCEPTION_GENERATOR")
    private BigInteger id;

    @Version
    @Column(name = "CALE_EXC_VERSION")
    @Basic(optional = false)
    private long version;

    @Column(name = "CALE_EXC_TYPE")
    @Convert(converter = CalendarExceptionTypeConverter.class)
    private CalendarExceptionType calendarExceptionType;

    @Column(name = "CALE_EXC_FRECU", insertable = false, updatable = false)
    private String frequencyType;

    @Column(name = "CALE_EXC_DESCR")
    private String description;

    @ManyToOne(optional = false)
    @JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
    private Calendar calendar;

}