"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.getReclaimEventAccountInstructionAsync = getReclaimEventAccountInstructionAsync;
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)())],
        ['nonce', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 32)],
        ['finalityThresholdExecuted', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 4)],
        ['feeExecuted', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 32)],
        ['expirationBlock', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 32)],
    ]), (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)())],
        ['nonce', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 32)],
        ['finalityThresholdExecuted', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 4)],
        ['feeExecuted', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 32)],
        ['expirationBlock', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 32)],
    ]);
}
function getReclaimEventAccountInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getReclaimEventAccountInstructionDataEncoder(), getReclaimEventAccountInstructionDataDecoder());
}
async function getReclaimEventAccountInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        rentFund: { value: input.rentFund ?? null, isWritable: true },
        messageTransmitter: {
            value: input.messageTransmitter ?? null,
            isWritable: true,
        },
        messageSentEventData: {
            value: input.messageSentEventData ?? null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: input.messageTransmitterProgram ?? null,
            isWritable: false,
        },
        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.rentFund.value) {
        accounts.rentFund.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([114, 101, 110, 116, 95, 102, 117, 110, 100])),
            ],
        });
    }
    if (!accounts.messageTransmitterProgram.value) {
        accounts.messageTransmitterProgram.value =
            'CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC';
    }
    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.rentFund),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.messageSentEventData),
            getAccountMeta(accounts.messageTransmitterProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getReclaimEventAccountInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function getReclaimEventAccountInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        rentFund: { value: input.rentFund ?? null, isWritable: true },
        messageTransmitter: {
            value: input.messageTransmitter ?? null,
            isWritable: true,
        },
        messageSentEventData: {
            value: input.messageSentEventData ?? null,
            isWritable: true,
        },
        messageTransmitterProgram: {
            value: input.messageTransmitterProgram ?? null,
            isWritable: false,
        },
        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.messageTransmitterProgram.value) {
        accounts.messageTransmitterProgram.value =
            'CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC';
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.rentFund),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.messageSentEventData),
            getAccountMeta(accounts.messageTransmitterProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getReclaimEventAccountInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseReclaimEventAccountInstruction(instruction) {
    if (instruction.accounts.length < 6) {
        // 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: {
            rentFund: getNextAccount(),
            messageTransmitter: getNextAccount(),
            messageSentEventData: getNextAccount(),
            messageTransmitterProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getReclaimEventAccountInstructionDataDecoder().decode(instruction.data),
    };
}
