const generateId = require("shortid");

class UploadGroup {
    constructor(metadata = {}) {
        this.groupId = generateId();
        
        // Strukturierte Metadaten
        this.year = metadata.year || new Date().getFullYear();
        this.title = metadata.title || "";
        this.description = metadata.description || "";
        this.name = metadata.name || "";
        
        // Backwards compatibility
        if (typeof metadata === 'string') {
            this.description = metadata;
            this.year = new Date().getFullYear();
            this.title = "";
            this.name = "";
        }
        
        this.uploadDate = new Date().toISOString();
        this.images = [];
    }
    
    addImage(fileName, originalName, uploadOrder) {
        this.images.push({
            fileName,
            originalName, 
            filePath: `/upload/${fileName}`,
            uploadOrder: uploadOrder || this.images.length + 1
        });
    }
    
    getImageCount() {
        return this.images.length;
    }
    
    toJSON() {
        return {
            groupId: this.groupId,
            year: this.year,
            title: this.title,
            description: this.description,
            name: this.name,
            uploadDate: this.uploadDate,
            images: this.images,
            imageCount: this.getImageCount()
        };
    }
}

module.exports = UploadGroup;