"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.REMOVE_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR = void 0;
exports.getRemoveRemoteTokenMessengerDiscriminatorBytes = getRemoveRemoteTokenMessengerDiscriminatorBytes;
exports.getRemoveRemoteTokenMessengerInstructionDataEncoder = getRemoveRemoteTokenMessengerInstructionDataEncoder;
exports.getRemoveRemoteTokenMessengerInstructionDataDecoder = getRemoveRemoteTokenMessengerInstructionDataDecoder;
exports.getRemoveRemoteTokenMessengerInstructionDataCodec = getRemoveRemoteTokenMessengerInstructionDataCodec;
exports.getRemoveRemoteTokenMessengerInstructionAsync = getRemoveRemoteTokenMessengerInstructionAsync;
exports.getRemoveRemoteTokenMessengerInstruction = getRemoveRemoteTokenMessengerInstruction;
exports.parseRemoveRemoteTokenMessengerInstruction = parseRemoveRemoteTokenMessengerInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.REMOVE_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR = new Uint8Array([
    65, 114, 66, 85, 169, 98, 177, 146,
]);
function getRemoveRemoteTokenMessengerDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.REMOVE_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR);
}
function getRemoveRemoteTokenMessengerInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({
        ...value,
        discriminator: exports.REMOVE_REMOTE_TOKEN_MESSENGER_DISCRIMINATOR,
    }));
}
function getRemoveRemoteTokenMessengerInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
    ]);
}
function getRemoveRemoteTokenMessengerInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getRemoveRemoteTokenMessengerInstructionDataEncoder(), getRemoveRemoteTokenMessengerInstructionDataDecoder());
}
async function getRemoveRemoteTokenMessengerInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payee: { value: input.payee ?? null, isWritable: true },
        owner: { value: input.owner ?? null, isWritable: false },
        tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
        remoteTokenMessenger: {
            value: input.remoteTokenMessenger ?? null,
            isWritable: true,
        },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Resolve default values.
    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.payee),
            getAccountMeta(accounts.owner),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.remoteTokenMessenger),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getRemoveRemoteTokenMessengerInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function getRemoveRemoteTokenMessengerInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payee: { value: input.payee ?? null, isWritable: true },
        owner: { value: input.owner ?? null, isWritable: false },
        tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
        remoteTokenMessenger: {
            value: input.remoteTokenMessenger ?? null,
            isWritable: true,
        },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.payee),
            getAccountMeta(accounts.owner),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.remoteTokenMessenger),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getRemoveRemoteTokenMessengerInstructionDataEncoder().encode({}),
    };
    return instruction;
}
function parseRemoveRemoteTokenMessengerInstruction(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: {
            payee: getNextAccount(),
            owner: getNextAccount(),
            tokenMessenger: getNextAccount(),
            remoteTokenMessenger: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getRemoveRemoteTokenMessengerInstructionDataDecoder().decode(instruction.data),
    };
}
