"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compatibleInterface = void 0;
const f_1 = require("../system/f/object/Keys/f");
const parser_1 = require("./parser");
const type_1 = require("./type");
function compatibleInterface(specs, a, b) {
    const aSpec = specs[a];
    const bSpec = specs[b];
    const { inputs: aI, outputs: aO } = aSpec;
    const { inputs: bI, outputs: bO } = bSpec;
    const aInputNames = (0, f_1.keys)(aI);
    const aOutputNames = (0, f_1.keys)(aO);
    const bInputNames = (0, f_1.keys)(bI);
    const bOutputNames = (0, f_1.keys)(bO);
    if (aInputNames.length !== bInputNames.length ||
        aOutputNames.length !== bOutputNames.length) {
        return false;
    }
    const aTypeInterface = (0, type_1.getSpecTypeInterfaceById)(a, specs);
    const bTypeInterface = (0, type_1.getSpecTypeInterfaceById)(b, specs);
    const aITypes = aInputNames.map((pinId) => aTypeInterface.input[pinId]);
    const aOTypes = aOutputNames.map((pinId) => aTypeInterface.output[pinId]);
    const bITypes = bInputNames.map((pinId) => bTypeInterface.input[pinId]);
    const bOTypes = bOutputNames.map((pinId) => bTypeInterface.output[pinId]);
    for (let i = 0; i < aITypes.length; i++) {
        const aIType = aITypes[i];
        const bIType = bITypes[i];
        const aOType = aOTypes[i];
        const bOType = bOTypes[i];
        if (!(0, parser_1.isTypeMatch)(specs, aIType, bIType) ||
            !(0, parser_1.isTypeMatch)(specs, aOType, bOType)) {
            return false;
        }
    }
    return true;
}
exports.compatibleInterface = compatibleInterface;
//# sourceMappingURL=compatibility.js.map