"use strict";
/**
 * This code was AUTOGENERATED using the kinobi library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun kinobi to update it.
 *
 * @see https://github.com/metaplex-foundation/kinobi
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEditionSize = exports.getEditionGpaBuilder = exports.safeFetchAllEdition = exports.fetchAllEdition = exports.safeFetchEdition = exports.fetchEdition = exports.deserializeEdition = exports.getEditionAccountDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
const types_1 = require("../types");
function getEditionAccountDataSerializer() {
    return (0, serializers_1.mapSerializer)((0, serializers_1.struct)([
        ['key', (0, types_1.getKeySerializer)()],
        ['parent', (0, serializers_1.publicKey)()],
        ['edition', (0, serializers_1.u64)()],
    ], { description: 'EditionAccountData' }), (value) => ({ ...value, key: types_1.Key.EditionV1 }));
}
exports.getEditionAccountDataSerializer = getEditionAccountDataSerializer;
function deserializeEdition(rawAccount) {
    return (0, umi_1.deserializeAccount)(rawAccount, getEditionAccountDataSerializer());
}
exports.deserializeEdition = deserializeEdition;
async function fetchEdition(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    (0, umi_1.assertAccountExists)(maybeAccount, 'Edition');
    return deserializeEdition(maybeAccount);
}
exports.fetchEdition = fetchEdition;
async function safeFetchEdition(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    return maybeAccount.exists ? deserializeEdition(maybeAccount) : null;
}
exports.safeFetchEdition = safeFetchEdition;
async function fetchAllEdition(context, publicKeys, options) {
    const maybeAccounts = await context.rpc.getAccounts(publicKeys.map((key) => (0, umi_1.publicKey)(key, false)), options);
    return maybeAccounts.map((maybeAccount) => {
        (0, umi_1.assertAccountExists)(maybeAccount, 'Edition');
        return deserializeEdition(maybeAccount);
    });
}
exports.fetchAllEdition = fetchAllEdition;
async function safeFetchAllEdition(context, publicKeys, options) {
    const maybeAccounts = await context.rpc.getAccounts(publicKeys.map((key) => (0, umi_1.publicKey)(key, false)), options);
    return maybeAccounts
        .filter((maybeAccount) => maybeAccount.exists)
        .map((maybeAccount) => deserializeEdition(maybeAccount));
}
exports.safeFetchAllEdition = safeFetchAllEdition;
function getEditionGpaBuilder(context) {
    const programId = context.programs.getPublicKey('mplTokenMetadata', 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
    return (0, umi_1.gpaBuilder)(context, programId)
        .registerFields({
        key: [0, (0, types_1.getKeySerializer)()],
        parent: [1, (0, serializers_1.publicKey)()],
        edition: [33, (0, serializers_1.u64)()],
    })
        .deserializeUsing((account) => deserializeEdition(account))
        .whereField('key', types_1.Key.EditionV1);
}
exports.getEditionGpaBuilder = getEditionGpaBuilder;
function getEditionSize() {
    return 41;
}
exports.getEditionSize = getEditionSize;
//# sourceMappingURL=edition.js.map