"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SET_MAX_MESSAGE_BODY_SIZE_DISCRIMINATOR = void 0;
exports.getSetMaxMessageBodySizeDiscriminatorBytes = getSetMaxMessageBodySizeDiscriminatorBytes;
exports.getSetMaxMessageBodySizeInstructionDataEncoder = getSetMaxMessageBodySizeInstructionDataEncoder;
exports.getSetMaxMessageBodySizeInstructionDataDecoder = getSetMaxMessageBodySizeInstructionDataDecoder;
exports.getSetMaxMessageBodySizeInstructionDataCodec = getSetMaxMessageBodySizeInstructionDataCodec;
exports.getSetMaxMessageBodySizeInstruction = getSetMaxMessageBodySizeInstruction;
exports.parseSetMaxMessageBodySizeInstruction = parseSetMaxMessageBodySizeInstruction;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
var programs_1 = require("../programs");
var shared_1 = require("../shared");
exports.SET_MAX_MESSAGE_BODY_SIZE_DISCRIMINATOR = new Uint8Array([
    168, 178, 8, 117, 217, 167, 219, 31,
]);
function getSetMaxMessageBodySizeDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SET_MAX_MESSAGE_BODY_SIZE_DISCRIMINATOR);
}
function getSetMaxMessageBodySizeInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["newMaxMessageBodySize", (0, kit_1.getU64Encoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.SET_MAX_MESSAGE_BODY_SIZE_DISCRIMINATOR })); });
}
function getSetMaxMessageBodySizeInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["newMaxMessageBodySize", (0, kit_1.getU64Decoder)()],
    ]);
}
function getSetMaxMessageBodySizeInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getSetMaxMessageBodySizeInstructionDataEncoder(), getSetMaxMessageBodySizeInstructionDataDecoder());
}
function getSetMaxMessageBodySizeInstruction(input, config) {
    var _a, _b, _c, _d, _e;
    var programAddress = (_a = config === null || config === void 0 ? void 0 : config.programAddress) !== null && _a !== void 0 ? _a : programs_1.MESSAGE_TRANSMITTER_PROGRAM_ADDRESS;
    var originalAccounts = {
        owner: { value: (_b = input.owner) !== null && _b !== void 0 ? _b : null, isWritable: false },
        messageTransmitter: {
            value: (_c = input.messageTransmitter) !== null && _c !== void 0 ? _c : null,
            isWritable: true,
        },
        eventAuthority: { value: (_d = input.eventAuthority) !== null && _d !== void 0 ? _d : null, isWritable: false },
        program: { value: (_e = input.program) !== null && _e !== void 0 ? _e : null, isWritable: false },
    };
    var accounts = originalAccounts;
    var args = tslib_1.__assign({}, input);
    var getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
    return Object.freeze({
        accounts: [
            getAccountMeta(accounts.owner),
            getAccountMeta(accounts.messageTransmitter),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        data: getSetMaxMessageBodySizeInstructionDataEncoder().encode(args),
        programAddress: programAddress,
    });
}
function parseSetMaxMessageBodySizeInstruction(instruction) {
    if (instruction.accounts.length < 4) {
        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: {
            owner: getNextAccount(),
            messageTransmitter: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getSetMaxMessageBodySizeInstructionDataDecoder().decode(instruction.data),
    };
}
//# sourceMappingURL=setMaxMessageBodySize.js.map