// tools/design-schema/platform-schemas.ts — Smart Contract schema generators
// SPEC-015a + SPEC-015b: Smart Contract schema generation.
// dbt and ML schemas moved to platform-schemas-b.ts for SOLID compliance.
export { isDbtSchema, generateDbtSchema, generateMLSchema } from './platform-schemas-b.js';
// === Smart Contract schema ===
/**
 * Returns true if the project is a smart contract project.
 */
export function isSmartContractSchema(knowledge) {
    const { projectCategory, framework, stack } = knowledge;
    if (projectCategory === 'smart-contract') {
        return true;
    }
    if (framework !== null && ['hardhat', 'foundry', 'anchor', 'move'].includes(framework)) {
        return true;
    }
    return stack.some((s) => ['solidity', 'hardhat', 'foundry', 'anchor', 'move'].includes(s.toLowerCase()));
}
/**
 * Returns true if the project is an ML/AI project.
 */
export function isMLSchema(knowledge) {
    const { projectCategory, stack } = knowledge;
    if (projectCategory === 'ml') {
        return true;
    }
    const mlIndicators = [
        'pytorch',
        'tensorflow',
        'scikit-learn',
        'sklearn',
        'langchain',
        'transformers',
        'huggingface',
    ];
    return stack.some((s) => mlIndicators.some((ind) => s.toLowerCase().includes(ind)));
}
// === Smart Contract schema generation ===
function buildStorageSection(entities) {
    const storageItems = entities.map((e) => {
        const name = e.charAt(0).toLowerCase() + e.slice(1);
        return `mapping(address => ${e}) public ${name}ByOwner;`;
    });
    storageItems.push('mapping(uint256 => address) public ownerOf;', 'uint256 private _tokenIdCounter;');
    return { category: 'Storage Variables', items: storageItems };
}
function buildEventSection(entities) {
    const events = entities.map((e) => `event ${e}Created(uint256 indexed id, address indexed owner);`);
    events.push('event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);', 'event Approval(address indexed owner, address indexed spender, uint256 value);');
    return { category: 'Events', items: events };
}
function buildStructSection(entities) {
    const structs = entities.map((e) => [
        `struct ${e} {`,
        '    uint256 id;',
        '    address owner;',
        '    uint256 createdAt;',
        '    bool active;',
        '}',
    ].join('\n'));
    return { category: 'Structs', items: structs };
}
function buildMappingSection(entities) {
    const mappings = entities.map((e) => {
        const plural = e.toLowerCase() + 's';
        return `mapping(uint256 => ${e}) private _${plural};`;
    });
    return { category: 'Mappings', items: mappings };
}
/**
 * Generate smart contract schema sections from entity names.
 */
export function generateSmartContractSchema(entityNames, knowledge) {
    const framework = knowledge.framework ?? 'hardhat';
    const sections = [
        buildStorageSection(entityNames),
        buildEventSection(entityNames),
        buildStructSection(entityNames),
        buildMappingSection(entityNames),
    ];
    const lines = [
        `## Smart Contract Schema (${framework})`,
        '',
        '```solidity',
        '// SPDX-License-Identifier: MIT',
        `pragma solidity ^0.8.24;`,
        '',
    ];
    for (const section of sections) {
        lines.push(`// --- ${section.category} ---`);
        for (const item of section.items) {
            lines.push(item);
        }
        lines.push('');
    }
    lines.push('```', '');
    lines.push('### Security Checklist', '');
    lines.push('- [ ] Reentrancy guard on state-changing functions (use `nonReentrant`)');
    lines.push('- [ ] Integer overflow protection (Solidity 0.8+ built-in, or SafeMath)');
    lines.push('- [ ] Access control (`Ownable`, `AccessControl`, or custom modifier)');
    lines.push('- [ ] Gas limits validated for loops');
    lines.push('- [ ] Front-running mitigated (commit-reveal scheme if needed)');
    lines.push('- [ ] Events emitted for all state changes');
    lines.push('');
    return lines.join('\n');
}
//# sourceMappingURL=platform-schemas.js.map