"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Path = require("path");
const ChildProcess = require("child_process");
const ACUtils = require("../../util/src");
/*
 *  各种应用场景的具体数据模型
*/
class AI18nItem {
    constructor(meta) {
        for (const key in meta) {
            if (meta.hasOwnProperty(key)) {
                if (!this.entries) {
                    this.entries = new Array();
                }
                const entry = new Object();
                entry.key = key;
                const plurals = this.pickPlurals(meta[key]);
                if (plurals) {
                    entry.plurals = plurals;
                }
                else {
                    entry.value = meta[key];
                }
                this.entries.push(entry);
            }
        }
    }
    pickPlurals(value) {
        return (value && value.indexOf('||||') !== -1) ? value.split('||||') : undefined;
    }
}
exports.AI18nItem = AI18nItem;
class AI18nPhrases {
    constructor(meta) {
        for (const key in meta) {
            if (meta.hasOwnProperty(key)) {
                if (!this.entries) {
                    this.entries = new Array();
                }
                const entry = new Object();
                entry.key = key;
                entry.value = new AI18nItem(meta[key]);
                this.entries.push(entry);
            }
        }
    }
}
exports.AI18nPhrases = AI18nPhrases;
/*
    编译接口（前提：brew install capnp）
*/
function build(jsonpath, outpath) {
    return new Promise((resolve, reject) => {
        const cmd = Path.join(ACUtils.ACUtils.respath, 'capnp/falcon_convert');
        const schema = Path.join(ACUtils.ACUtils.respath, 'capnp/cube.capnp');
        const result = ChildProcess.spawnSync(cmd, [schema, jsonpath, outpath]);
        if (result.status !== 0) {
            reject(new Error(result.stderr));
        }
        else {
            resolve(result.stdout);
        }
    });
}
exports.build = build;
//# sourceMappingURL=falcon-capnp.js.map