package de.assecutor.votianlt.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * MongoDB document for caching LLM translations. Stores the original text, all
 * translations keyed by language code, and the insertion timestamp.
 */
@Data
@NoArgsConstructor
@Document(collection = "translation_cache")
public class TranslationCacheEntry {

    @Id
    private ObjectId id;

    /**
     * The original text that was translated.
     */
    @Indexed(unique = true)
    @Field("source_text")
    private String sourceText;

    /**
     * Translations keyed by language code (e.g. "de", "en", "fr").
     */
    @Field("translations")
    private Map<String, String> translations;

    /**
     * When this entry was inserted into the cache.
     */
    @Indexed
    @Field("inserted_at")
    private LocalDateTime insertedAt;

    public TranslationCacheEntry(String sourceText, Map<String, String> translations) {
        this.sourceText = sourceText;
        this.translations = translations;
        this.insertedAt = LocalDateTime.now();
    }
}
