"use strict";
/**
 * XLSX converter entry point.
 *
 * Reads a dxkit JSON report (licenses or bom) and renders the
 * 15-column BOM-format XLSX the customer's workflow expects. Shape
 * detection is lightweight — top-level fields only — so the CLI's
 * `vyuh-dxkit to-xlsx <json-file>` can route without being told
 * which analyzer produced the input.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.toBomXlsx = exports.BOM_COLUMNS = exports.toLicensesXlsx = void 0;
exports.detectReportKind = detectReportKind;
exports.toXlsx = toXlsx;
var licenses_1 = require("./licenses");
Object.defineProperty(exports, "toLicensesXlsx", { enumerable: true, get: function () { return licenses_1.toLicensesXlsx; } });
Object.defineProperty(exports, "BOM_COLUMNS", { enumerable: true, get: function () { return licenses_1.BOM_COLUMNS; } });
var bom_1 = require("./bom");
Object.defineProperty(exports, "toBomXlsx", { enumerable: true, get: function () { return bom_1.toBomXlsx; } });
function detectReportKind(data) {
    if (!data || typeof data !== 'object')
        return 'unknown';
    const r = data;
    // BomReport: { entries: BomEntry[] } where each entry has both
    // `licenseType` (license-side) AND `vulns` (vuln-side). The vulns
    // field is the unique discriminator vs licenses.
    if (Array.isArray(r.entries)) {
        const sample = r.entries[0];
        if (sample && typeof sample.licenseType === 'string' && Array.isArray(sample.vulns)) {
            return 'bom';
        }
    }
    // LicensesReport: { findings: LicenseFinding[] } where each finding
    // carries `licenseType` but NO `vulns` field.
    if (Array.isArray(r.findings)) {
        const sample = r.findings[0];
        if (sample && typeof sample.licenseType === 'string')
            return 'licenses';
    }
    return 'unknown';
}
/**
 * Render any supported dxkit JSON report as an XLSX buffer. Throws if
 * the input shape isn't recognised so the CLI can surface the error
 * to the user rather than producing garbage output.
 */
async function toXlsx(data) {
    const kind = detectReportKind(data);
    if (kind === 'bom') {
        const { toBomXlsx } = await Promise.resolve().then(() => __importStar(require('./bom')));
        return toBomXlsx(data);
    }
    if (kind === 'licenses') {
        const { toLicensesXlsx } = await Promise.resolve().then(() => __importStar(require('./licenses')));
        return toLicensesXlsx(data);
    }
    throw new Error('Unrecognised report shape. Supported inputs: licenses (vyuh-dxkit licenses --detailed) or bom (vyuh-dxkit bom --detailed).');
}
//# sourceMappingURL=index.js.map