package org.raddatz.familienarchiv.document;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.UUID;

@Entity
@Table(name = "document_versions")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DocumentVersion {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private UUID id;

    @Column(name = "document_id", nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private UUID documentId;

    @Column(name = "saved_at", nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime savedAt;

    @Column(name = "editor_id")
    private UUID editorId;

    @Column(name = "editor_name", nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private String editorName;

    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "jsonb", nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private String snapshot;

    @JdbcTypeCode(SqlTypes.JSON)
    @Column(name = "changed_fields", columnDefinition = "jsonb", nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private String changedFields;
}
