/**
 * @module sync peer innerspace helpers
 */
import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
import { SYNC_PEER_INNERSPACE_ATOM } from './sync-peer-innerspace-constants.mjs';
/**
 * Constructs the standard 'ib' string for a Sync Peer Innerspace stone.
 */
export async function getSyncPeerInnerspaceIb({ data, }) {
    const lc = `[${getSyncPeerInnerspaceIb.name}]`;
    try {
        if (!data) {
            throw new Error(`data required (E: 7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d)`);
        }
        if (!data.classname) {
            throw new Error(`invalid data. data.classname required. (E: 3aad38bfe23866c2d8c1ca66b03d9126)`);
        }
        // sync_peer_innerspace
        const ib = [
            SYNC_PEER_INNERSPACE_ATOM,
            data.classname,
        ].join(' ');
        return ib;
    }
    catch (error) {
        console.error(`${lc} ${extractErrorMsg(error)}`);
        throw error;
    }
}
/**
 * Parses a standard Sync Peer Innerspace 'ib' string.
 */
export async function parseSyncPeerInnerspaceIb({ ib, }) {
    const lc = `[${parseSyncPeerInnerspaceIb.name}]`;
    try {
        if (ib !== SYNC_PEER_INNERSPACE_ATOM) {
            throw new Error(`Atom mismatch. Expected ${SYNC_PEER_INNERSPACE_ATOM}. Got ${ib}. (E: 8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e)`);
        }
        const pieces = ib.split(' ');
        if (pieces.length !== 2) {
            throw new Error(`invalid ib. expected 2 pieces: atom and classname (E: f9c0c8067368444bac69f5777eeaa826)`);
        }
        const [atom, classname] = pieces;
        if (atom !== SYNC_PEER_INNERSPACE_ATOM) {
            throw new Error(`invalid ib. atom (${atom}) is expected to be ${SYNC_PEER_INNERSPACE_ATOM} (E: fda078ef3a0853629eb22e48a01a8826)`);
        }
        return { atom, classname };
    }
    catch (error) {
        console.error(`${lc} ${extractErrorMsg(error)}`);
        throw error;
    }
}
//# sourceMappingURL=sync-peer-innerspace-helpers.mjs.map