package com.bytesw.bytebot.model;

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;
import java.time.OffsetDateTime;

@Audited
@Entity
@Table(name = "AVB_BUSINESS_PARAMETER_CONFIG")
@NamedQuery(name = "BusinessParameterConfiguration.findByPK", query = "Select u from BusinessParameterConfiguration u where u.id = ?1")
@Getter @Setter @EqualsAndHashCode @ToString(exclude = "id")
public class BusinessParameterConfiguration implements Serializable, Comparable<BusinessParameterConfiguration> {

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

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

    @Column(name = "BUPC_FROM", nullable = false)
    private OffsetDateTime from;

    @Column(name = "BUPC_TO")
    private OffsetDateTime to;

    @Column(name = "BUPC_VALUE", nullable = false)
    private String value;

    @ManyToOne(optional = false)
    @JoinColumn(name = "BUPA_ID", referencedColumnName = "BUPA_ID", nullable = false)
    private BusinessParameter businessParameter;

    @Override
    public int compareTo(BusinessParameterConfiguration o) {
        return from.compareTo(o.getFrom());
    }
}
