package de.assecutor.votianlt.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

/**
 * Stores invoice template data for a user. Contains the JSON representation of
 * the canvas elements.
 */
@Document(collection = "invoice_templates")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class InvoiceTemplate {

    @Id
    private String id;

    /**
     * The user ID this template belongs to
     */
    private String userId;

    /**
     * Template name (optional, for future use if multiple templates are supported)
     */
    private String name;

    /**
     * JSON string containing the template data (canvas elements)
     */
    private String templateData;

    /**
     * When the template was created
     */
    private LocalDateTime createdAt;

    /**
     * When the template was last updated
     */
    private LocalDateTime updatedAt;

    /**
     * Version for optimistic locking
     */
    private Long version;

    public InvoiceTemplate(String userId, String name, String templateData) {
        this.userId = userId;
        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();
    }
}
