/**
 * 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
 */
import { __assign } from "tslib";
import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, transformEncoder, } from "@solana/kit";
import { MESSAGE_TRANSMITTER_PROGRAM_ADDRESS } from "../programs";
import { getAccountMetaFactory } from "../shared";
export var SEND_MESSAGE_WITH_CALLER_DISCRIMINATOR = new Uint8Array([
    212, 47, 34, 52, 91, 32, 176, 204,
]);
export function getSendMessageWithCallerDiscriminatorBytes() {
    return fixEncoderSize(getBytesEncoder(), 8).encode(SEND_MESSAGE_WITH_CALLER_DISCRIMINATOR);
}
export function getSendMessageWithCallerInstructionDataEncoder() {
    return transformEncoder(getStructEncoder([
        ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
        ["destinationDomain", getU32Encoder()],
        ["recipient", getAddressEncoder()],
        ["messageBody", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())],
        ["destinationCaller", getAddressEncoder()],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: SEND_MESSAGE_WITH_CALLER_DISCRIMINATOR })); });
}
export function getSendMessageWithCallerInstructionDataDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["destinationDomain", getU32Decoder()],
        ["recipient", getAddressDecoder()],
        ["messageBody", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())],
        ["destinationCaller", getAddressDecoder()],
    ]);
}
export function getSendMessageWithCallerInstructionDataCodec() {
    return combineCodec(getSendMessageWithCallerInstructionDataEncoder(), getSendMessageWithCallerInstructionDataDecoder());
}
export function getSendMessageWithCallerInstruction(input, config) {
    var _a, _b, _c, _d, _e, _f, _g;
    // Program address.
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : MESSAGE_TRANSMITTER_PROGRAM_ADDRESS;
    // Original accounts.
    var originalAccounts = {
        eventRentPayer: { value: (_b = input.eventRentPayer) !== null && _b !== void 0 ? _b : null, isWritable: true },
        senderAuthorityPda: {
            value: (_c = input.senderAuthorityPda) !== null && _c !== void 0 ? _c : null,
            isWritable: false,
        },
        messageTransmitter: {
            value: (_d = input.messageTransmitter) !== null && _d !== void 0 ? _d : null,
            isWritable: true,
        },
        messageSentEventData: {
            value: (_e = input.messageSentEventData) !== null && _e !== void 0 ? _e : null,
            isWritable: true,
        },
        senderProgram: { value: (_f = input.senderProgram) !== null && _f !== void 0 ? _f : null, isWritable: false },
        systemProgram: { value: (_g = input.systemProgram) !== null && _g !== void 0 ? _g : null, isWritable: false },
    };
    var accounts = originalAccounts;
    // Original args.
    var args = __assign({}, input);
    // Resolve default values.
    if (!accounts.systemProgram.value) {
        accounts.systemProgram.value =
            "11111111111111111111111111111111";
    }
    var getAccountMeta = getAccountMetaFactory(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.eventRentPayer),
            getAccountMeta(accounts.senderAuthorityPda),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.messageSentEventData),
            getAccountMeta(accounts.senderProgram),
            getAccountMeta(accounts.systemProgram),
        ],
        data: getSendMessageWithCallerInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
export function parseSendMessageWithCallerInstruction(instruction) {
    if (instruction.accounts.length < 6) {
        // TODO: Coded error.
        throw new Error("Not enough accounts");
    }
    var accountIndex = 0;
    var getNextAccount = function () {
        var accountMeta = instruction.accounts[accountIndex];
        accountIndex += 1;
        return accountMeta;
    };
    return {
        programAddress: instruction.programAddress,
        accounts: {
            eventRentPayer: getNextAccount(),
            senderAuthorityPda: getNextAccount(),
            messageTransmitter: getNextAccount(),
            messageSentEventData: getNextAccount(),
            senderProgram: getNextAccount(),
            systemProgram: getNextAccount(),
        },
        data: getSendMessageWithCallerInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=sendMessageWithCaller.js.map