"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.coverPinAction = exports.makeUnplugPinAction = exports.makePlugPinAction = exports.makeCoverPinSetAction = exports.makeExposePinSetAction = exports.setPinSetFunctionalAction = exports.setPinSetNameAction = exports.exposePinAction = exports.makeRemoveUnitsAction = exports.makeRemoveUnitAction = exports.makeAddUnitsAction = exports.makeAddUnitAction = exports.COLLAPSE_UNITS = exports.EXPAND_UNIT = exports.REMOVE_UNIT_MERGES = exports.SET_UNIT_METADATA = exports.SET_METADATA = exports.SET_PIN_SET_REF = exports.SET_PIN_SET_FUNCTIONAL = exports.SET_PIN_SET_NAME = exports.SET_UNIT_ERR = exports.SET_UNIT_OUTPUT_IGNORED = exports.SET_UNIT_INPUT_IGNORED = exports.SET_UNIT_PIN_IGNORED = exports.SET_UNIT_INPUT_CONSTANT = exports.SET_UNIT_PIN_CONSTANT = exports.REMOVE_UNIT_PIN_DATA = exports.SET_UNIT_PIN_DATA = exports.SET_UNIT_OUTPUT_CONSTANT = exports.SET_UNIT_OUTPUT = exports.SET_UNIT_INPUT = exports.TOGGLE_EXPOSE_OUTPUT = exports.TOGGLE_EXPOSE_INPUT = exports.PLUG_PIN = exports.UNPLUG_PIN = exports.COVER_PIN = exports.COVER_PIN_SET = exports.EXPOSE_PIN_SET = exports.EXPOSE_PIN = exports.MERGE_MERGES = exports.REMOVE_MERGES = exports.REMOVE_MERGE = exports.REMOVE_PIN_FROM_MERGE = exports.ADD_PIN_TO_MERGE = exports.ADD_MERGES = exports.ADD_MERGE = exports.REMOVE_UNITS = exports.REMOVE_UNIT = exports.ADD_UNITS = exports.ADD_UNIT = void 0;
exports.reverseAction = exports.makeRemoveUnitMergesAction = exports.makeMergeMergesAction = exports.makeRemovePinFromMergeAction = exports.makeAddPinToMergeAction = exports.makeRemoveMergesAction = exports.makeAddMergesAction = exports.makeRemoveMergeAction = exports.makeAddMergeAction = exports.setMetadataAction = exports.setUnitMetadataAction = exports.removeUnitPinDataAction = exports.makeSetUnitOutputIgnoredAction = exports.makeSetUnitInputIgnoredAction = exports.makeSetUnitPinIgnoredAction = exports.setUnitPinIgnoredAction = exports.makeSetUnitOutputConstantAction = exports.makeSetUnitInputConstantAction = exports.makeSetUnitPinConstantAction = exports.setUnitOutputConstantAction = exports.setUnitPinDataAction = void 0;
const CodePathNotImplemented_1 = require("../../exception/CodePathNotImplemented");
const f_1 = require("../../system/f/object/Keys/f");
exports.ADD_UNIT = 'addUnit';
exports.ADD_UNITS = 'addUnits';
exports.REMOVE_UNIT = 'removeUnit';
exports.REMOVE_UNITS = 'removeUnits';
exports.ADD_MERGE = 'addMerge';
exports.ADD_MERGES = 'addMerges';
exports.ADD_PIN_TO_MERGE = 'addPinToMerge';
exports.REMOVE_PIN_FROM_MERGE = 'removePinFromMerge';
exports.REMOVE_MERGE = 'removeMerge';
exports.REMOVE_MERGES = 'removeMerges';
exports.MERGE_MERGES = 'mergeMerges';
exports.EXPOSE_PIN = 'exposePin';
exports.EXPOSE_PIN_SET = 'exposePinSet';
exports.COVER_PIN_SET = 'coverPinSet';
exports.COVER_PIN = 'coverPin';
exports.UNPLUG_PIN = 'unplugPin';
exports.PLUG_PIN = 'plugPin';
exports.TOGGLE_EXPOSE_INPUT = 'toggleExposeInput';
exports.TOGGLE_EXPOSE_OUTPUT = 'toggleExposeOutput';
exports.SET_UNIT_INPUT = 'setUnitInput';
exports.SET_UNIT_OUTPUT = 'setUnitOutput';
exports.SET_UNIT_OUTPUT_CONSTANT = 'setUnitOutputConstant';
exports.SET_UNIT_PIN_DATA = 'setUnitPinData';
exports.REMOVE_UNIT_PIN_DATA = 'removeUnitPinData';
exports.SET_UNIT_PIN_CONSTANT = 'setUnitPinConstant';
exports.SET_UNIT_INPUT_CONSTANT = 'setUnitInputConstant';
exports.SET_UNIT_PIN_IGNORED = 'setUnitPinIgnored';
exports.SET_UNIT_INPUT_IGNORED = 'setUnitInputIgnored';
exports.SET_UNIT_OUTPUT_IGNORED = 'setUnitOutputIgnored';
exports.SET_UNIT_ERR = 'setUnitErr';
exports.SET_PIN_SET_NAME = 'setPinSetName';
exports.SET_PIN_SET_FUNCTIONAL = 'setPinSetFunctional';
exports.SET_PIN_SET_REF = 'setPinSetRef';
exports.SET_METADATA = 'setMetadata';
exports.SET_UNIT_METADATA = 'setUnitMetadata';
exports.REMOVE_UNIT_MERGES = 'removeUnitMerges';
exports.EXPAND_UNIT = 'expandUnit';
exports.COLLAPSE_UNITS = 'collapseUnits';
const makeAddUnitAction = (id, unit, position, pinPosition, layoutPositon, parentId) => {
    return {
        type: exports.ADD_UNIT,
        data: {
            id,
            unit,
            position,
            pinPosition,
            layoutPositon,
            parentId,
        },
    };
};
exports.makeAddUnitAction = makeAddUnitAction;
const makeAddUnitsAction = (units) => {
    return {
        type: exports.ADD_UNITS,
        data: {
            units,
        },
    };
};
exports.makeAddUnitsAction = makeAddUnitsAction;
const makeRemoveUnitAction = (id, unit, position, pinPosition, layoutPositon, parentId) => {
    return {
        type: exports.REMOVE_UNIT,
        data: { id, unit, position, pinPosition, layoutPositon, parentId },
    };
};
exports.makeRemoveUnitAction = makeRemoveUnitAction;
const makeRemoveUnitsAction = (ids) => {
    return {
        type: exports.REMOVE_UNITS,
        data: { ids },
    };
};
exports.makeRemoveUnitsAction = makeRemoveUnitsAction;
const exposePinAction = (type, id, subPinId, subPin) => {
    return {
        type: exports.EXPOSE_PIN,
        data: { type, id, subPinId, subPin },
    };
};
exports.exposePinAction = exposePinAction;
const setPinSetNameAction = (type, id, functional) => {
    return {
        type: exports.SET_PIN_SET_NAME,
        data: { type, id, functional },
    };
};
exports.setPinSetNameAction = setPinSetNameAction;
const setPinSetFunctionalAction = (type, id, functional) => {
    return {
        type: exports.SET_PIN_SET_FUNCTIONAL,
        data: { type, id, functional },
    };
};
exports.setPinSetFunctionalAction = setPinSetFunctionalAction;
const makeExposePinSetAction = (type, id, pin) => {
    return {
        type: exports.EXPOSE_PIN_SET,
        data: { type, id, pin },
    };
};
exports.makeExposePinSetAction = makeExposePinSetAction;
const makeCoverPinSetAction = (type, id) => {
    return {
        type: exports.COVER_PIN_SET,
        data: { type, id },
    };
};
exports.makeCoverPinSetAction = makeCoverPinSetAction;
const makePlugPinAction = (type, id, subPinId, subPinSpec) => {
    return {
        type: exports.PLUG_PIN,
        data: { type, id, subPinId, subPinSpec },
    };
};
exports.makePlugPinAction = makePlugPinAction;
const makeUnplugPinAction = (type, id, subPinId) => {
    return {
        type: exports.UNPLUG_PIN,
        data: { type, id, subPinId },
    };
};
exports.makeUnplugPinAction = makeUnplugPinAction;
const coverPinAction = (id, type, subPinId) => {
    return {
        type: exports.COVER_PIN,
        data: { type, id, subPinId },
    };
};
exports.coverPinAction = coverPinAction;
const setUnitPinDataAction = (unitId, type, pinId, data) => {
    return {
        type: exports.SET_UNIT_PIN_DATA,
        data: {
            unitId,
            type,
            pinId,
            data,
        },
    };
};
exports.setUnitPinDataAction = setUnitPinDataAction;
const setUnitOutputConstantAction = (unitId, pinId, constant) => {
    return {
        type: exports.SET_UNIT_OUTPUT,
        data: {
            unitId,
            pinId,
            constant,
        },
    };
};
exports.setUnitOutputConstantAction = setUnitOutputConstantAction;
const makeSetUnitPinConstantAction = (unitId, type, pinId, constant) => {
    return {
        type: exports.SET_UNIT_PIN_CONSTANT,
        data: {
            unitId,
            type,
            pinId,
            constant,
        },
    };
};
exports.makeSetUnitPinConstantAction = makeSetUnitPinConstantAction;
const makeSetUnitInputConstantAction = (unitId, pinId, constant) => {
    return {
        type: exports.SET_UNIT_INPUT_CONSTANT,
        data: {
            unitId,
            pinId,
            constant,
        },
    };
};
exports.makeSetUnitInputConstantAction = makeSetUnitInputConstantAction;
const makeSetUnitOutputConstantAction = (unitId, pinId, constant) => {
    return {
        type: exports.SET_UNIT_OUTPUT_CONSTANT,
        data: {
            unitId,
            pinId,
            constant,
        },
    };
};
exports.makeSetUnitOutputConstantAction = makeSetUnitOutputConstantAction;
const setUnitPinIgnoredAction = (unitId, type, pinId, ignored) => {
    return {
        type: exports.SET_UNIT_PIN_IGNORED,
        data: {
            unitId,
            type,
            pinId,
            ignored,
        },
    };
};
exports.setUnitPinIgnoredAction = setUnitPinIgnoredAction;
const makeSetUnitPinIgnoredAction = (unitId, type, pinId, ignored) => {
    return {
        type: exports.SET_UNIT_PIN_IGNORED,
        data: {
            unitId,
            type,
            pinId,
            ignored,
        },
    };
};
exports.makeSetUnitPinIgnoredAction = makeSetUnitPinIgnoredAction;
const makeSetUnitInputIgnoredAction = (unitId, pinId, ignored) => {
    return {
        type: exports.SET_UNIT_INPUT_IGNORED,
        data: {
            unitId,
            pinId,
            ignored,
        },
    };
};
exports.makeSetUnitInputIgnoredAction = makeSetUnitInputIgnoredAction;
const makeSetUnitOutputIgnoredAction = (unitId, pinId, ignored) => {
    return {
        type: exports.SET_UNIT_OUTPUT_IGNORED,
        data: {
            unitId,
            pinId,
            ignored,
        },
    };
};
exports.makeSetUnitOutputIgnoredAction = makeSetUnitOutputIgnoredAction;
const removeUnitPinDataAction = (unitId, type, pinId) => {
    return {
        type: exports.REMOVE_UNIT_PIN_DATA,
        data: {
            unitId,
            type,
            pinId,
        },
    };
};
exports.removeUnitPinDataAction = removeUnitPinDataAction;
const setUnitMetadataAction = (id, path, value) => {
    return {
        type: exports.SET_UNIT_METADATA,
        data: {
            id,
            path,
            value,
        },
    };
};
exports.setUnitMetadataAction = setUnitMetadataAction;
const setMetadataAction = (path, value) => {
    return {
        type: exports.SET_METADATA,
        data: {
            path,
            value,
        },
    };
};
exports.setMetadataAction = setMetadataAction;
const makeAddMergeAction = (id, merge, position) => {
    return {
        type: exports.ADD_MERGE,
        data: {
            id,
            merge,
            position,
        },
    };
};
exports.makeAddMergeAction = makeAddMergeAction;
const makeRemoveMergeAction = (id, merge, position) => {
    return {
        type: exports.REMOVE_MERGE,
        data: {
            id,
            merge,
            position,
        },
    };
};
exports.makeRemoveMergeAction = makeRemoveMergeAction;
const makeAddMergesAction = (merges) => {
    return {
        type: exports.ADD_MERGES,
        data: {
            merges,
        },
    };
};
exports.makeAddMergesAction = makeAddMergesAction;
const makeRemoveMergesAction = (ids) => {
    return {
        type: exports.REMOVE_MERGES,
        data: {
            ids,
        },
    };
};
exports.makeRemoveMergesAction = makeRemoveMergesAction;
const makeAddPinToMergeAction = (id, type, unitId, pinId) => {
    return {
        type: exports.ADD_PIN_TO_MERGE,
        data: {
            id,
            unitId,
            type,
            pinId,
        },
    };
};
exports.makeAddPinToMergeAction = makeAddPinToMergeAction;
const makeRemovePinFromMergeAction = (id, type, unitId, pinId) => {
    return {
        type: exports.REMOVE_PIN_FROM_MERGE,
        data: {
            id,
            unitId,
            type,
            pinId,
        },
    };
};
exports.makeRemovePinFromMergeAction = makeRemovePinFromMergeAction;
const makeMergeMergesAction = (a, b) => {
    return {
        type: exports.MERGE_MERGES,
        data: {
            a,
            b,
        },
    };
};
exports.makeMergeMergesAction = makeMergeMergesAction;
const makeRemoveUnitMergesAction = (id) => {
    return {
        type: exports.REMOVE_UNIT_MERGES,
        data: {
            id,
        },
    };
};
exports.makeRemoveUnitMergesAction = makeRemoveUnitMergesAction;
const reverseAction = ({ type, data }) => {
    switch (type) {
        case exports.ADD_UNIT:
            return (0, exports.makeRemoveUnitAction)(data.id, data, data.position, data.pinPosition, data.layoutPosition, data.parentId);
        case exports.ADD_UNITS:
            return (0, exports.makeRemoveUnitsAction)((0, f_1.keys)(data.units));
        case exports.REMOVE_UNIT:
            return (0, exports.makeAddUnitAction)(data.id, data.unit, data.position, data.pinPosition, data.layoutPosition, data.parentId);
        case exports.REMOVE_UNITS:
            return (0, exports.makeAddUnitsAction)(data.ids.reduce((acc, id) => {
                acc[id] = data.units[id];
                return acc;
            }, {}));
        case exports.REMOVE_UNIT_MERGES:
            return (0, exports.makeAddMergesAction)(data.merges);
        case exports.ADD_MERGE:
            return (0, exports.makeRemoveMergeAction)(data.id, data.merge, data.position);
        case exports.ADD_MERGES:
            return (0, exports.makeRemoveMergesAction)((0, f_1.keys)(data.merges));
        case exports.ADD_PIN_TO_MERGE:
            return (0, exports.makeRemovePinFromMergeAction)(data.id, data.type, data.unitId, data.pinId);
        case exports.REMOVE_MERGE:
            return (0, exports.makeAddMergeAction)(data.id, data.merge, data.position);
        case exports.REMOVE_PIN_FROM_MERGE:
            return (0, exports.makeAddPinToMergeAction)(data.id, data.type, data.unitId, data.pinId);
        case exports.MERGE_MERGES:
            return (0, exports.makeMergeMergesAction)(data.a, data.b);
        case exports.EXPOSE_PIN_SET:
            return (0, exports.makeCoverPinSetAction)(data.type, data.id);
        case exports.COVER_PIN_SET:
            return (0, exports.makeExposePinSetAction)(data.type, data.id, data.plug);
        case exports.PLUG_PIN:
            return (0, exports.makeUnplugPinAction)(data.type, data.id, data.subPinId);
        case exports.UNPLUG_PIN:
            return (0, exports.makePlugPinAction)(data.type, data.id, data.subPinId, data.subPinSpec);
        case exports.SET_UNIT_PIN_CONSTANT:
            return (0, exports.makeSetUnitPinConstantAction)(data.unitId, data.type, data.pinId, !data.constant);
        case exports.SET_UNIT_INPUT_CONSTANT:
            return (0, exports.makeSetUnitInputConstantAction)(data.unitId, data.pinId, !data.constant);
        case exports.SET_UNIT_OUTPUT_CONSTANT:
            return (0, exports.makeSetUnitOutputConstantAction)(data.unitId, data.pinId, !data.constant);
        case exports.SET_UNIT_INPUT_IGNORED:
            return (0, exports.makeSetUnitInputIgnoredAction)(data.unitId, data.pinId, !data.ignored);
        case exports.SET_UNIT_OUTPUT_IGNORED:
            return (0, exports.makeSetUnitOutputIgnoredAction)(data.unitId, data.pinId, !data.ignored);
        case exports.SET_UNIT_PIN_IGNORED:
            return (0, exports.makeSetUnitPinIgnoredAction)(data.unitId, data.type, data.pinId, !data.ignored);
        default:
            throw new CodePathNotImplemented_1.CodePathNotImplementedError();
    }
};
exports.reverseAction = reverseAction;
//# sourceMappingURL=spec.js.map