// Path: core/infrastructure/src/main/java/org/hesperides/core/infrastructure/mongo/technos/TechnoDocument.java
// @Data
// @Document(collection = TECHNO)
// @NoArgsConstructor
// public class TechnoDocument {
//     @Id
//     private String id;
//     private KeyDocument key;
//     private List<TemplateDocument> templates;
//     private List<AbstractPropertyDocument> properties;
// 
//     TechnoDocument(String id, Techno techno) {
//         this.id = id;
//         this.key = new KeyDocument(techno.getKey());
//         this.templates = TemplateDocument.fromDomainInstances(techno.getTemplates());
//     }
// 
//     public static List<TechnoView> toTechnoViews(List<TechnoDocument> technos) {
//         return Optional.ofNullable(technos)
//                 .orElseGet(Collections::emptyList)
//                 .stream()
//                 .map(TechnoDocument::toTechnoView)
//                 .collect(Collectors.toList());
//     }
// 
//     public static List<Techno> toDomainInstances(List<TechnoDocument> technoDocuments) {
//         return Optional.ofNullable(technoDocuments)
//                 .orElseGet(Collections::emptyList)
//                 .stream()
//                 .map(TechnoDocument::toDomainInstance)
//                 .collect(Collectors.toList());
//     }
// 
//     public Techno toDomainInstance() {
//         TemplateContainer.Key technoKey = getDomainKey();
//         return new Techno(
//                 technoKey,
//                 TemplateDocument.toDomainInstances(templates, technoKey)
//         );
//     }
// 
//     TechnoView toTechnoView() {
//         TemplateContainer.Key technoKey = getDomainKey();
//         return new TechnoView(key.getName(), key.getVersion(), key.isWorkingCopy(),
//                 TemplateDocument.toTemplateViews(templates, technoKey));
//     }
// 
//     public void addTemplate(TemplateDocument templateDocument) {
//         if (templates == null) {
//             templates = new ArrayList<>();
//         }
//         templates.add(templateDocument);
//     }
// 
//     public void updateTemplate(TemplateDocument updatedTemplateDocument) {
//         removeTemplate(updatedTemplateDocument.getName());
//         addTemplate(updatedTemplateDocument);
//     }
// 
//     void removeTemplate(String templateName) {
//         templates.removeIf(templateDocument -> templateDocument.getName().equalsIgnoreCase(templateName));
//     }
// 
//     void extractPropertiesAndSave(MongoTechnoRepository technoRepository) {
//         this.setProperties(extractPropertiesFromTemplates());
//         technoRepository.save(this);
//     }
// 
//     private List<AbstractPropertyDocument> extractPropertiesFromTemplates() {
//         TemplateContainer.Key technoKey = getDomainKey();
//         List<Template> templates = TemplateDocument.toDomainInstances(this.templates, technoKey);
//         List<AbstractProperty> abstractProperties = AbstractProperty.extractPropertiesFromTemplates(templates, key.toString());
//         return AbstractPropertyDocument.fromDomainInstances(abstractProperties);
//     }
// 
//     Techno.Key getDomainKey() {
//         return new Techno.Key(key.getName(), key.getVersion(), TemplateContainer.getVersionType(key.isWorkingCopy()));
//     }
// }


import lombok.Data;
import lombok.NoArgsConstructor;
import org.hesperides.core.domain.modules.entities.Module;
import org.hesperides.core.domain.modules.queries.ModulePasswordProperties;
import org.hesperides.core.domain.modules.queries.ModulePropertiesView;
import org.hesperides.core.domain.modules.queries.ModuleView;
import org.hesperides.core.domain.templatecontainers.entities.AbstractProperty;
import org.hesperides.core.domain.templatecontainers.entities.Template;
import org.hesperides.core.domain.templatecontainers.entities.TemplateContainer;
import org.hesperides.core.infrastructure.mongo.technos.TechnoDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.AbstractPropertyDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.KeyDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.PropertyDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.TemplateDocument;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toSet;
import static org.hesperides.core.infrastructure.mongo.Collections.MODULE;
package org.hesperides.core.infrastructure.mongo.modules;




@Data
@Document(collection = MODULE)
@NoArgsConstructor
public class ModuleDocument {

    @Id
    private String id;
    private KeyDocument key;
    private List<TemplateDocument> templates;
    @DBRef
// Path: core/infrastructure/src/main/java/org/hesperides/core/infrastructure/mongo/technos/TechnoDocument.java
// @Data
// @Document(collection = TECHNO)
// @NoArgsConstructor
// public class TechnoDocument {
//     @Id
//     private String id;
//     private KeyDocument key;
//     private List<TemplateDocument> templates;
//     private List<AbstractPropertyDocument> properties;
// 
//     TechnoDocument(String id, Techno techno) {
//         this.id = id;
//         this.key = new KeyDocument(techno.getKey());
//         this.templates = TemplateDocument.fromDomainInstances(techno.getTemplates());
//     }
// 
//     public static List<TechnoView> toTechnoViews(List<TechnoDocument> technos) {
//         return Optional.ofNullable(technos)
//                 .orElseGet(Collections::emptyList)
//                 .stream()
//                 .map(TechnoDocument::toTechnoView)
//                 .collect(Collectors.toList());
//     }
// 
//     public static List<Techno> toDomainInstances(List<TechnoDocument> technoDocuments) {
//         return Optional.ofNullable(technoDocuments)
//                 .orElseGet(Collections::emptyList)
//                 .stream()
//                 .map(TechnoDocument::toDomainInstance)
//                 .collect(Collectors.toList());
//     }
// 
//     public Techno toDomainInstance() {
//         TemplateContainer.Key technoKey = getDomainKey();
//         return new Techno(
//                 technoKey,
//                 TemplateDocument.toDomainInstances(templates, technoKey)
//         );
//     }
// 
//     TechnoView toTechnoView() {
//         TemplateContainer.Key technoKey = getDomainKey();
//         return new TechnoView(key.getName(), key.getVersion(), key.isWorkingCopy(),
//                 TemplateDocument.toTemplateViews(templates, technoKey));
//     }
// 
//     public void addTemplate(TemplateDocument templateDocument) {
//         if (templates == null) {
//             templates = new ArrayList<>();
//         }
//         templates.add(templateDocument);
//     }
// 
//     public void updateTemplate(TemplateDocument updatedTemplateDocument) {
//         removeTemplate(updatedTemplateDocument.getName());
//         addTemplate(updatedTemplateDocument);
//     }
// 
//     void removeTemplate(String templateName) {
//         templates.removeIf(templateDocument -> templateDocument.getName().equalsIgnoreCase(templateName));
//     }
// 
//     void extractPropertiesAndSave(MongoTechnoRepository technoRepository) {
//         this.setProperties(extractPropertiesFromTemplates());
//         technoRepository.save(this);
//     }
// 
//     private List<AbstractPropertyDocument> extractPropertiesFromTemplates() {
//         TemplateContainer.Key technoKey = getDomainKey();
//         List<Template> templates = TemplateDocument.toDomainInstances(this.templates, technoKey);
//         List<AbstractProperty> abstractProperties = AbstractProperty.extractPropertiesFromTemplates(templates, key.toString());
//         return AbstractPropertyDocument.fromDomainInstances(abstractProperties);
//     }
// 
//     Techno.Key getDomainKey() {
//         return new Techno.Key(key.getName(), key.getVersion(), TemplateContainer.getVersionType(key.isWorkingCopy()));
//     }
// }


// Path: core/infrastructure/src/main/java/org/hesperides/core/infrastructure/mongo/modules/ModuleDocument.java
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hesperides.core.domain.modules.entities.Module;
import org.hesperides.core.domain.modules.queries.ModulePasswordProperties;
import org.hesperides.core.domain.modules.queries.ModulePropertiesView;
import org.hesperides.core.domain.modules.queries.ModuleView;
import org.hesperides.core.domain.templatecontainers.entities.AbstractProperty;
import org.hesperides.core.domain.templatecontainers.entities.Template;
import org.hesperides.core.domain.templatecontainers.entities.TemplateContainer;
import org.hesperides.core.infrastructure.mongo.technos.TechnoDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.AbstractPropertyDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.KeyDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.PropertyDocument;
import org.hesperides.core.infrastructure.mongo.templatecontainers.TemplateDocument;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toSet;
import static org.hesperides.core.infrastructure.mongo.Collections.MODULE;

package org.hesperides.core.infrastructure.mongo.modules;




@Data
@Document(collection = MODULE)
@NoArgsConstructor
public class ModuleDocument {

    @Id
    private String id;
    private KeyDocument key;
    private List<TemplateDocument> templates;
    @DBRef
    private List<TechnoDocument> technos;