const GAME_FW_SET = new Set(['unity', 'godot', 'unreal', 'bevy', 'phaser', 'pygame']);
/**
 * Returns true if the project is a game that needs game-specific schema.
 */
export function isGameSchema(knowledge) {
    if (knowledge.projectCategory === 'game') {
        return true;
    }
    return knowledge.framework !== null && GAME_FW_SET.has(knowledge.framework);
}
/**
 * Generate game-specific schema design including save system, leaderboards, inventory, achievements.
 */
export function generateGameSchema(entities, knowledge) {
    const engine = knowledge.framework ?? 'unknown';
    const schema = buildGameSchemaDesign(engine, entities);
    const output = [
        `## Game Schema Design — ${engine.charAt(0).toUpperCase() + engine.slice(1)}`,
        '',
        '### Save System',
        ...formatSaveSystem(schema.saveSystem, engine),
        '',
        '### Leaderboard',
        ...formatLeaderboard(schema.leaderboard),
        '',
        '### Inventory',
        ...formatInventory(schema.inventory),
        '',
        '### Achievements',
        ...formatAchievements(schema.achievements, entities),
        '',
        '### Player Stats',
        ...formatPlayerStats(schema.playerStats),
        '',
        '### Schema JSON',
        '```json',
        JSON.stringify(schema, null, 2),
        '```',
    ];
    return output.join('\n');
}
function buildGameSchemaDesign(engine, entities) {
    const saveStrategy = getSaveStrategy(engine);
    const statsFields = extractStatsFields(entities);
    return {
        engine,
        saveSystem: {
            strategy: saveStrategy,
            fields: ['level', 'score', 'playerName', 'timestamp', ...statsFields.slice(0, 3)],
            autoSave: true,
            slots: 3,
        },
        leaderboard: {
            type: engine === 'phaser' || engine === 'pygame' ? 'local' : 'both',
            fields: ['rank', 'playerName', 'score', 'level', 'timestamp'],
            maxEntries: 100,
        },
        inventory: {
            itemFields: ['id', 'name', 'type', 'quantity', 'rarity', 'durability'],
            maxSlots: 36,
            stackable: true,
            /* v8 ignore next */
            persistence: saveStrategy === 'cloud-sync' ? 'cloud' : 'save-file',
        },
        achievements: buildAchievements(entities),
        playerStats: {
            fields: [
                'health',
                'maxHealth',
                'level',
                'experience',
                'currency',
                ...statsFields.slice(0, 5),
            ],
            /* v8 ignore next */
            persistence: saveStrategy === 'cloud-sync' ? 'cloud' : 'save-file',
        },
    };
}
function getSaveStrategy(engine) {
    if (engine === 'unity') {
        return 'scriptable-object';
    }
    if (engine === 'godot') {
        return 'local-file';
    }
    return 'local-file';
}
function extractStatsFields(entities) {
    const statKeywords = [
        'health',
        'hp',
        'attack',
        'defense',
        'speed',
        'mana',
        'stamina',
        'xp',
        'gold',
    ];
    const found = [];
    for (const entity of entities) {
        const lower = entity.toLowerCase();
        for (const kw of statKeywords) {
            if (lower.includes(kw) && !found.includes(kw)) {
                found.push(kw);
            }
        }
    }
    return found;
}
function buildAchievements(entities) {
    const achievements = [
        {
            id: 'first_play',
            name: 'First Adventure',
            condition: 'Play the game for the first time',
            type: 'flag',
        },
        {
            id: 'high_score',
            name: 'High Scorer',
            condition: 'Reach the top 10 leaderboard',
            type: 'score',
        },
        {
            id: 'completionist',
            name: 'Completionist',
            condition: 'Complete all main objectives',
            type: 'count',
        },
    ];
    for (const entity of entities.slice(0, 3)) {
        achievements.push({
            id: `collect_${entity.toLowerCase()}`,
            name: `${entity} Collector`,
            condition: `Collect 10 ${entity} items`,
            type: 'count',
        });
    }
    return achievements;
}
function formatSaveSystem(save, engine) {
    const lines = [
        `- **Strategy**: \`${save.strategy}\` ${engine === 'unity' ? '(Unity ScriptableObject / PlayerPrefs)' : engine === 'godot' ? '(Godot save_game())' : '(local JSON/binary file)'}`,
        `- **Fields**: ${save.fields.join(', ')}`,
        /* v8 ignore next */
        `- **Auto-save**: ${save.autoSave ? 'yes (every level transition + periodic)' : 'no (manual only)'}`,
        `- **Save slots**: ${String(save.slots)} (slot 0 = auto-save)`,
    ];
    return lines;
}
function formatLeaderboard(lb) {
    return [
        `- **Type**: ${lb.type} (${lb.type === 'both' ? 'local cache + remote sync' : lb.type})`,
        `- **Fields**: ${lb.fields.join(', ')}`,
        `- **Max entries**: ${String(lb.maxEntries)} (LRU eviction for oldest entries)`,
    ];
}
function formatInventory(inv) {
    return [
        `- **Item fields**: ${inv.itemFields.join(', ')}`,
        /* v8 ignore next */
        `- **Max slots**: ${String(inv.maxSlots)} (${inv.stackable ? 'stackable items' : 'no stacking'})`,
        `- **Persistence**: ${inv.persistence}`,
    ];
}
function formatAchievements(achievements, _entities) {
    return achievements.map((a) => `- **${a.name}** (\`${a.id}\`): ${a.condition} [type: ${a.type}]`);
}
function formatPlayerStats(stats) {
    return [
        `- **Fields**: ${stats.fields.join(', ')}`,
        `- **Persistence**: ${stats.persistence} (synced on save)`,
    ];
}
//# sourceMappingURL=design-schema-games.js.map