package org.raddatz.familienarchiv.tag;

import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;

// prevents infinite recursion in JSON serialization; see ADR-022 for lazy-fetch context
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Tag {
    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private UUID id;

    @Column(unique = true, nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private String name;

    /** UUID of the parent tag, or null for root-level tags. */
    @Column(name = "parent_id")
    private UUID parentId;

    /** Color token name (e.g. "sage"), only set on root-level tags. Null means no color. */
    private String color;

    /**
     * Import identity key, keyed on the canonical tag_path. Null for manually created tags;
     * unique among non-null values. The importer (Phase 3) uses it for idempotent re-import.
     */
    @Column(name = "source_ref")
    private String sourceRef;
}
