"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.doCI = doCI;
const utils_1 = require("../utils");
const project = (0, utils_1.getProjectName)();
function doCI(args) {
    (0, utils_1.printHeader)('Cell CI');
    const sub = args[1] || 'summary';
    if (sub === 'summary') {
        const days = parseInt(args[2] || '7');
        (0, utils_1.httpGet)(`/ci/summary?project=${project}&days=${days}`).then((result) => {
            console.log(utils_1.C.bold('  CI Summary:'));
            console.log(`    Total builds: ${result.totalBuilds || 0}`);
            console.log(`    Success rate: ${result.successRate || 0}%`);
            console.log(`    Avg duration: ${result.avgDuration || 0}s`);
        }).catch(() => (0, utils_1.printWarning)('Failed to get CI summary'));
        return;
    }
    if (sub === 'failures') {
        (0, utils_1.httpGet)(`/ci/failures?project=${project}`).then((result) => {
            if (result.failures && result.failures.length > 0) {
                for (const f of result.failures.slice(0, 10)) {
                    console.log(`  [${f.severity}] ${f.pattern}`);
                    (0, utils_1.printDim)(`    Count: ${f.count} | Last: ${f.lastSeen}`);
                }
            }
            else {
                (0, utils_1.printDim)('No CI failures recorded');
            }
        }).catch(() => (0, utils_1.printWarning)('Failed to get CI failures'));
        return;
    }
    if (sub === 'report') {
        const status = args[2] || 'success';
        const stage = args[3] || 'build';
        (0, utils_1.httpPost)('/ci/report', {
            project,
            branch: 'main',
            buildId: `cli-${Date.now()}`,
            status,
            stage,
            duration: 0,
            commitHash: '',
            commitMessage: '',
            author: 'cli',
            ciPlatform: 'local',
        }).then(() => {
            (0, utils_1.printSuccess)(`CI ${status} reported for ${stage}`);
        }).catch(() => (0, utils_1.printWarning)('Failed to report CI'));
        return;
    }
    // Default: show summary
    (0, utils_1.httpGet)(`/ci/summary?project=${project}&days=7`).then((result) => {
        console.log(JSON.stringify(result, null, 2));
    }).catch(() => (0, utils_1.printWarning)('Failed to get CI info'));
}
//# sourceMappingURL=ci.js.map