"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.IS_NONCE_USED_DISCRIMINATOR = void 0;
exports.getIsNonceUsedDiscriminatorBytes = getIsNonceUsedDiscriminatorBytes;
exports.getIsNonceUsedInstructionDataEncoder = getIsNonceUsedInstructionDataEncoder;
exports.getIsNonceUsedInstructionDataDecoder = getIsNonceUsedInstructionDataDecoder;
exports.getIsNonceUsedInstructionDataCodec = getIsNonceUsedInstructionDataCodec;
exports.getIsNonceUsedInstruction = getIsNonceUsedInstruction;
exports.parseIsNonceUsedInstruction = parseIsNonceUsedInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.IS_NONCE_USED_DISCRIMINATOR = new Uint8Array([
    144, 72, 107, 148, 35, 218, 31, 187,
]);
function getIsNonceUsedDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.IS_NONCE_USED_DISCRIMINATOR);
}
function getIsNonceUsedInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({ ...value, discriminator: exports.IS_NONCE_USED_DISCRIMINATOR }));
}
function getIsNonceUsedInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
    ]);
}
function getIsNonceUsedInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getIsNonceUsedInstructionDataEncoder(), getIsNonceUsedInstructionDataDecoder());
}
function getIsNonceUsedInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.MESSAGE_TRANSMITTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        usedNonce: { value: input.usedNonce ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [getAccountMeta(accounts.usedNonce)],
        programAddress,
        data: getIsNonceUsedInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function parseIsNonceUsedInstruction(instruction) {
    if (instruction.accounts.length < 1) {
        // 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: {
            usedNonce: getNextAccount(),
        },
        data: getIsNonceUsedInstructionDataDecoder().decode(instruction.data),
    };
}
