"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.RECLAIM_EVENT_ACCOUNT_DISCRIMINATOR = void 0;
exports.getReclaimEventAccountDiscriminatorBytes = getReclaimEventAccountDiscriminatorBytes;
exports.getReclaimEventAccountInstructionDataEncoder = getReclaimEventAccountInstructionDataEncoder;
exports.getReclaimEventAccountInstructionDataDecoder = getReclaimEventAccountInstructionDataDecoder;
exports.getReclaimEventAccountInstructionDataCodec = getReclaimEventAccountInstructionDataCodec;
exports.getReclaimEventAccountInstruction = getReclaimEventAccountInstruction;
exports.parseReclaimEventAccountInstruction = parseReclaimEventAccountInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.RECLAIM_EVENT_ACCOUNT_DISCRIMINATOR = new Uint8Array([
    94, 198, 180, 159, 131, 236, 15, 174,
]);
function getReclaimEventAccountDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.RECLAIM_EVENT_ACCOUNT_DISCRIMINATOR);
}
function getReclaimEventAccountInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ['attestation', (0, kit_1.addEncoderSizePrefix)((0, kit_1.getBytesEncoder)(), (0, kit_1.getU32Encoder)())],
        [
            'destinationMessage',
            (0, kit_1.addEncoderSizePrefix)((0, kit_1.getBytesEncoder)(), (0, kit_1.getU32Encoder)()),
        ],
    ]), (value) => ({
        ...value,
        discriminator: exports.RECLAIM_EVENT_ACCOUNT_DISCRIMINATOR,
    }));
}
function getReclaimEventAccountInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ['attestation', (0, kit_1.addDecoderSizePrefix)((0, kit_1.getBytesDecoder)(), (0, kit_1.getU32Decoder)())],
        [
            'destinationMessage',
            (0, kit_1.addDecoderSizePrefix)((0, kit_1.getBytesDecoder)(), (0, kit_1.getU32Decoder)()),
        ],
    ]);
}
function getReclaimEventAccountInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getReclaimEventAccountInstructionDataEncoder(), getReclaimEventAccountInstructionDataDecoder());
}
function getReclaimEventAccountInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.MESSAGE_TRANSMITTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payee: { value: input.payee ?? null, isWritable: true },
        messageTransmitter: {
            value: input.messageTransmitter ?? null,
            isWritable: true,
        },
        messageSentEventData: {
            value: input.messageSentEventData ?? null,
            isWritable: true,
        },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.payee),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.messageSentEventData),
        ],
        programAddress,
        data: getReclaimEventAccountInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseReclaimEventAccountInstruction(instruction) {
    if (instruction.accounts.length < 3) {
        // 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: {
            payee: getNextAccount(),
            messageTransmitter: getNextAccount(),
            messageSentEventData: getNextAccount(),
        },
        data: getReclaimEventAccountInstructionDataDecoder().decode(instruction.data),
    };
}
