package com.betriebsratkanzlei.legalconsenthub.application_form_version

import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationForm
import com.betriebsratkanzlei.legalconsenthub.user.User
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormStatus
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EntityListeners
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import org.hibernate.annotations.OnDelete
import org.hibernate.annotations.OnDeleteAction
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime
import java.util.UUID

@Entity
@EntityListeners(AuditingEntityListener::class)
class ApplicationFormVersion(
    @Id
    @GeneratedValue
    var id: UUID? = null,
    @ManyToOne
    @JoinColumn(name = "application_form_id", nullable = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    var applicationForm: ApplicationForm,
    @Column(nullable = false)
    var versionNumber: Int,
    @Column(nullable = false)
    var name: String,
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    var status: ApplicationFormStatus,
    @Column(nullable = false)
    var organizationId: String,
    @Column(nullable = false, columnDefinition = "TEXT")
    var snapshotData: String,
    @ManyToOne
    @JoinColumn(name = "created_by_id", nullable = false)
    var createdBy: User,
    @CreatedDate
    @Column(nullable = false)
    var createdAt: LocalDateTime? = null,
)
