"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.updateMetadataAccountV2 = exports.getUpdateMetadataAccountV2InstructionDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
const shared_1 = require("../shared");
const types_1 = require("../types");
function getUpdateMetadataAccountV2InstructionDataSerializer() {
    return (0, serializers_1.mapSerializer)((0, serializers_1.struct)([
        ['discriminator', (0, serializers_1.u8)()],
        ['data', (0, serializers_1.option)((0, types_1.getDataV2Serializer)())],
        ['newUpdateAuthority', (0, serializers_1.option)((0, serializers_1.publicKey)())],
        ['primarySaleHappened', (0, serializers_1.option)((0, serializers_1.bool)())],
        ['isMutable', (0, serializers_1.option)((0, serializers_1.bool)())],
    ], { description: 'UpdateMetadataAccountV2InstructionData' }), (value) => ({
        ...value,
        discriminator: 15,
        data: value.data ?? (0, umi_1.none)(),
        newUpdateAuthority: value.newUpdateAuthority ?? (0, umi_1.none)(),
        primarySaleHappened: value.primarySaleHappened ?? (0, umi_1.none)(),
        isMutable: value.isMutable ?? (0, umi_1.none)(),
    }));
}
exports.getUpdateMetadataAccountV2InstructionDataSerializer = getUpdateMetadataAccountV2InstructionDataSerializer;
// Instruction.
function updateMetadataAccountV2(context, input) {
    // Program ID.
    const programId = context.programs.getPublicKey('mplTokenMetadata', 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
    // Accounts.
    const resolvedAccounts = {
        metadata: {
            index: 0,
            isWritable: true,
            value: input.metadata ?? null,
        },
        updateAuthority: {
            index: 1,
            isWritable: false,
            value: input.updateAuthority ?? null,
        },
    };
    // Arguments.
    const resolvedArgs = { ...input };
    // Default values.
    if (!resolvedAccounts.updateAuthority.value) {
        resolvedAccounts.updateAuthority.value = context.identity;
    }
    // Accounts in order.
    const orderedAccounts = Object.values(resolvedAccounts).sort((a, b) => a.index - b.index);
    // Keys and Signers.
    const [keys, signers] = (0, shared_1.getAccountMetasAndSigners)(orderedAccounts, 'programId', programId);
    // Data.
    const data = getUpdateMetadataAccountV2InstructionDataSerializer().serialize(resolvedArgs);
    // Bytes Created On Chain.
    const bytesCreatedOnChain = 0;
    return (0, umi_1.transactionBuilder)([
        { instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
    ]);
}
exports.updateMetadataAccountV2 = updateMetadataAccountV2;
//# sourceMappingURL=updateMetadataAccountV2.js.map