// Import vertical organization
export * from './verticals/index.js';
/**
 * Creates template metadata from a DataDomain instance for UI presentation
 */
export function createTemplateMetadata(domain, templateInfo) {
    const structure = analyzeDomainStructure(domain);
    return {
        id: templateInfo.id,
        name: templateInfo.name,
        description: templateInfo.description,
        createdAt: templateInfo.createdAt,
        updatedAt: templateInfo.updatedAt,
        version: templateInfo.version,
        author: templateInfo.author,
        tags: templateInfo.tags || [],
        structure,
    };
}
/**
 * Analyzes a DataDomain to extract structural information for UI presentation
 */
export function analyzeDomainStructure(domain) {
    const namespaces = [];
    let totalEntities = 0;
    let totalProperties = 0;
    let totalAssociations = 0;
    // Analyze each namespace
    for (const namespace of domain.listNamespaces()) {
        const namespaceInfo = analyzeNamespace(namespace);
        namespaces.push(namespaceInfo);
        totalEntities += namespaceInfo.entityCount;
        totalProperties += namespaceInfo.models.reduce((sum, model) => sum + model.entities.reduce((entitySum, entity) => entitySum + entity.propertyCount, 0), 0);
        totalAssociations += namespaceInfo.models.reduce((sum, model) => sum + model.entities.reduce((entitySum, entity) => entitySum + entity.associationCount, 0), 0);
    }
    return {
        domain: {
            name: domain.info.name || 'Unnamed Domain',
            description: domain.info.description,
            totalEntities,
            totalProperties,
            totalAssociations,
        },
        namespaces,
    };
}
/**
 * Analyzes a DomainNamespace to extract information for UI presentation
 */
function analyzeNamespace(namespace) {
    const models = [];
    let entityCount = 0;
    // Analyze each model in the namespace
    for (const model of namespace.listModels()) {
        const modelInfo = analyzeModel(model);
        models.push(modelInfo);
        entityCount += modelInfo.entityCount;
    }
    return {
        name: namespace.info.name || 'Unnamed Namespace',
        displayName: namespace.info.displayName,
        description: namespace.info.description,
        modelCount: models.length,
        entityCount,
        models,
    };
}
/**
 * Analyzes a DomainModel to extract information for UI presentation
 */
function analyzeModel(model) {
    const entities = [];
    // Analyze each entity in the model
    for (const entity of model.listEntities()) {
        const entityInfo = analyzeEntity(entity);
        entities.push(entityInfo);
    }
    return {
        name: model.info.name || 'Unnamed Model',
        displayName: model.info.displayName,
        description: model.info.description,
        entityCount: entities.length,
        entities,
    };
}
/**
 * Analyzes a DomainEntity to extract information for UI presentation
 */
function analyzeEntity(entity) {
    const properties = [];
    const associations = [];
    // Analyze properties
    for (const property of entity.listProperties()) {
        properties.push(analyzeProperty(property));
    }
    // Analyze associations
    for (const association of entity.listAssociations()) {
        associations.push(analyzeAssociation(association));
    }
    return {
        name: entity.info.name || 'Unnamed Entity',
        displayName: entity.info.displayName,
        description: entity.info.description,
        propertyCount: properties.length,
        associationCount: associations.length,
        deprecated: entity.deprecated,
        properties,
        associations,
        semantics: entity.semantics?.map((s) => s.id) || [],
    };
}
/**
 * Analyzes a DomainProperty to extract information for UI presentation
 */
function analyzeProperty(property) {
    const semantics = property.semantics?.map((s) => s.id) || [];
    // Extract enum values if present
    let enumValues;
    if (property.schema?.enum && Array.isArray(property.schema.enum)) {
        enumValues = property.schema.enum.map((v) => String(v));
    }
    // Extract default value
    let defaultValue;
    if (property.schema?.defaultValue) {
        if (property.schema.defaultValue.type === 'literal') {
            defaultValue = String(property.schema.defaultValue.value);
        }
    }
    return {
        name: property.info.name || 'Unnamed Property',
        displayName: property.info.displayName,
        description: property.info.description,
        type: property.type || 'string',
        required: property.required,
        multiple: property.multiple,
        primary: property.primary,
        unique: property.unique,
        readOnly: property.readOnly,
        writeOnly: property.writeOnly,
        deprecated: property.deprecated,
        semantics,
        enumValues,
        defaultValue,
    };
}
/**
 * Analyzes a DomainAssociation to extract information for UI presentation
 */
function analyzeAssociation(association) {
    const semantics = association.semantics?.map((s) => s.id) || [];
    // Get target entity names
    const targetEntities = association.targets?.map((target) => {
        // Try to resolve the target entity to get its name
        const targetEntity = association.domain.findEntity(target.key);
        return targetEntity?.info.name || target.key;
    }) || [];
    // Determine cardinality description
    let cardinality = 'One-to-One';
    if (association.multiple) {
        cardinality = 'One-to-Many';
    }
    // Note: Many-to-Many would typically be determined by looking at the reverse association
    // but for simplicity in UI presentation, we'll use the current association's multiplicity
    return {
        name: association.info.name || 'Unnamed Association',
        displayName: association.info.displayName,
        description: association.info.description,
        required: association.required,
        multiple: association.multiple,
        readOnly: association.readOnly,
        targetEntities,
        semantics,
        cardinality,
    };
}
//# sourceMappingURL=index.js.map