import { Edition, Key, MasterEditionV1, MasterEditionV2, Metadata, } from '@metaplex-solarti/mpl-token-metadata';
import { getAccountParsingAndAssertingFunction, getAccountParsingFunction, } from '../../types';
import { NotYetImplementedError } from '../../errors';
/** @group Account Helpers */
export const parseMetadataAccount = getAccountParsingFunction(Metadata);
/** @group Account Helpers */
export const toMetadataAccount = getAccountParsingAndAssertingFunction(Metadata);
const originalOrPrintEditionAccountParser = {
    name: 'MasterEditionV1 | MasterEditionV2 | Edition',
    deserialize: (data, offset = 0) => {
        if ((data === null || data === void 0 ? void 0 : data[0]) === Key.MasterEditionV1) {
            return MasterEditionV1.deserialize(data, offset);
        }
        else if ((data === null || data === void 0 ? void 0 : data[0]) === Key.MasterEditionV2) {
            return MasterEditionV2.deserialize(data, offset);
        }
        return Edition.deserialize(data, offset);
    },
    fromArgs() {
        throw new NotYetImplementedError();
    },
};
/** @group Account Helpers */
export const parseOriginalOrPrintEditionAccount = getAccountParsingFunction(originalOrPrintEditionAccountParser);
/** @group Account Helpers */
export const toOriginalOrPrintEditionAccount = getAccountParsingAndAssertingFunction(originalOrPrintEditionAccountParser);
/** @group Account Helpers */
export const isOriginalEditionAccount = (account) => {
    return 'maxSupply' in account.data;
};
/** @group Account Helpers */
export const isPrintEditionAccount = (account) => {
    return !isOriginalEditionAccount(account);
};
const originalEditionAccountParser = {
    name: 'MasterEditionV1 | MasterEditionV2',
    deserialize: (data, offset = 0) => {
        if ((data === null || data === void 0 ? void 0 : data[0]) === Key.MasterEditionV1) {
            return MasterEditionV1.deserialize(data, offset);
        }
        return MasterEditionV2.deserialize(data, offset);
    },
    fromArgs() {
        throw new NotYetImplementedError();
    },
};
/** @group Account Helpers */
export const parseOriginalEditionAccount = getAccountParsingFunction(originalEditionAccountParser);
/** @group Account Helpers */
export const toOriginalEditionAccount = getAccountParsingAndAssertingFunction(originalEditionAccountParser);
/** @group Account Helpers */
export const parsePrintEditionAccount = getAccountParsingFunction(Edition);
/** @group Account Helpers */
export const toPrintEditionAccount = getAccountParsingAndAssertingFunction(Edition);
//# sourceMappingURL=accounts.js.map