"use strict";
/**
 * This code was AUTOGENERATED using the codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SET_MAX_BURN_AMOUNT_PER_MESSAGE_DISCRIMINATOR = void 0;
exports.getSetMaxBurnAmountPerMessageDiscriminatorBytes = getSetMaxBurnAmountPerMessageDiscriminatorBytes;
exports.getSetMaxBurnAmountPerMessageInstructionDataEncoder = getSetMaxBurnAmountPerMessageInstructionDataEncoder;
exports.getSetMaxBurnAmountPerMessageInstructionDataDecoder = getSetMaxBurnAmountPerMessageInstructionDataDecoder;
exports.getSetMaxBurnAmountPerMessageInstructionDataCodec = getSetMaxBurnAmountPerMessageInstructionDataCodec;
exports.getSetMaxBurnAmountPerMessageInstructionAsync = getSetMaxBurnAmountPerMessageInstructionAsync;
exports.getSetMaxBurnAmountPerMessageInstruction = getSetMaxBurnAmountPerMessageInstruction;
exports.parseSetMaxBurnAmountPerMessageInstruction = parseSetMaxBurnAmountPerMessageInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.SET_MAX_BURN_AMOUNT_PER_MESSAGE_DISCRIMINATOR = new Uint8Array([
    30, 128, 145, 240, 70, 237, 109, 207,
]);
function getSetMaxBurnAmountPerMessageDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SET_MAX_BURN_AMOUNT_PER_MESSAGE_DISCRIMINATOR);
}
function getSetMaxBurnAmountPerMessageInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ['burnLimitPerMessage', (0, kit_1.getU64Encoder)()],
    ]), (value) => ({
        ...value,
        discriminator: exports.SET_MAX_BURN_AMOUNT_PER_MESSAGE_DISCRIMINATOR,
    }));
}
function getSetMaxBurnAmountPerMessageInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ['burnLimitPerMessage', (0, kit_1.getU64Decoder)()],
    ]);
}
function getSetMaxBurnAmountPerMessageInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getSetMaxBurnAmountPerMessageInstructionDataEncoder(), getSetMaxBurnAmountPerMessageInstructionDataDecoder());
}
async function getSetMaxBurnAmountPerMessageInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        tokenController: {
            value: input.tokenController ?? null,
            isWritable: false,
        },
        tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
        localToken: { value: input.localToken ?? null, isWritable: true },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    // Resolve default values.
    if (!accounts.eventAuthority.value) {
        accounts.eventAuthority.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([
                    95, 95, 101, 118, 101, 110, 116, 95, 97, 117, 116, 104, 111, 114,
                    105, 116, 121,
                ])),
            ],
        });
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.tokenController),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getSetMaxBurnAmountPerMessageInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function getSetMaxBurnAmountPerMessageInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        tokenController: {
            value: input.tokenController ?? null,
            isWritable: false,
        },
        tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
        localToken: { value: input.localToken ?? null, isWritable: true },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.tokenController),
            getAccountMeta(accounts.tokenMinter),
            getAccountMeta(accounts.localToken),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getSetMaxBurnAmountPerMessageInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseSetMaxBurnAmountPerMessageInstruction(instruction) {
    if (instruction.accounts.length < 5) {
        // TODO: Coded error.
        throw new Error('Not enough accounts');
    }
    let accountIndex = 0;
    const getNextAccount = () => {
        const accountMeta = instruction.accounts[accountIndex];
        accountIndex += 1;
        return accountMeta;
    };
    return {
        programAddress: instruction.programAddress,
        accounts: {
            tokenController: getNextAccount(),
            tokenMinter: getNextAccount(),
            localToken: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getSetMaxBurnAmountPerMessageInstructionDataDecoder().decode(instruction.data),
    };
}
