package dp.kotul.templategroupsbackend.model.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import javax.persistence.CascadeType
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.OneToOne

@Entity
class TemplateVariable(
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "templateVariableSeq")
        @Column(name = "templateVariableId")
        val templateVariableId: Int = 0,

        @JsonIgnore
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "templateId")
        val template: Template,

        @Column(nullable = false)
        val templateVariableExtId: String,

        @Column(nullable = false)
        var included: Boolean,

        @OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true)
        @JoinColumn(name = "variableSourceId")
        var variableSource: VariableSource?
)
