package de.assecutor.pdftool.template;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

/**
 * Ein Rechnungstemplate des Rechnungsgenerators in MongoDB. Das eigentliche
 * Template ist die JSON-Serialisierung der Canvas-Elemente im Feld
 * {@link #templateData}.
 */
@Document(collection = "invoice_templates")
public class InvoiceTemplate {

    @Id
    private String id;

    /** Eindeutiger Name des Templates, z. B. "standard". */
    @Indexed(unique = true)
    private String name;

    /** JSON der Canvas-Elemente ({"elements": [...]}). */
    private String templateData;

    private LocalDateTime createdAt;

    private LocalDateTime updatedAt;

    public InvoiceTemplate() {
    }

    public InvoiceTemplate(String name, String templateData) {
        this.name = name;
        this.templateData = templateData;
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }

    public void updateTemplate(String templateData) {
        this.templateData = templateData;
        this.updatedAt = LocalDateTime.now();
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getTemplateData() {
        return templateData;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
}
