"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.UNDENYLIST_ACCOUNT_DISCRIMINATOR = void 0;
exports.getUndenylistAccountDiscriminatorBytes = getUndenylistAccountDiscriminatorBytes;
exports.getUndenylistAccountInstructionDataEncoder = getUndenylistAccountInstructionDataEncoder;
exports.getUndenylistAccountInstructionDataDecoder = getUndenylistAccountInstructionDataDecoder;
exports.getUndenylistAccountInstructionDataCodec = getUndenylistAccountInstructionDataCodec;
exports.getUndenylistAccountInstructionAsync = getUndenylistAccountInstructionAsync;
exports.getUndenylistAccountInstruction = getUndenylistAccountInstruction;
exports.parseUndenylistAccountInstruction = parseUndenylistAccountInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.UNDENYLIST_ACCOUNT_DISCRIMINATOR = new Uint8Array([
    57, 36, 43, 168, 62, 172, 33, 39,
]);
function getUndenylistAccountDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.UNDENYLIST_ACCOUNT_DISCRIMINATOR);
}
function getUndenylistAccountInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ['account', (0, kit_1.getAddressEncoder)()],
    ]), (value) => ({ ...value, discriminator: exports.UNDENYLIST_ACCOUNT_DISCRIMINATOR }));
}
function getUndenylistAccountInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ['account', (0, kit_1.getAddressDecoder)()],
    ]);
}
function getUndenylistAccountInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getUndenylistAccountInstructionDataEncoder(), getUndenylistAccountInstructionDataDecoder());
}
async function getUndenylistAccountInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payer: { value: input.payer ?? null, isWritable: true },
        denylister: { value: input.denylister ?? null, isWritable: false },
        tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
        denylistAccount: { value: input.denylistAccount ?? null, isWritable: true },
        systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) {
        accounts.systemProgram.value =
            '11111111111111111111111111111111';
    }
    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.payer),
            getAccountMeta(accounts.denylister),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.denylistAccount),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getUndenylistAccountInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function getUndenylistAccountInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        payer: { value: input.payer ?? null, isWritable: true },
        denylister: { value: input.denylister ?? null, isWritable: false },
        tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
        denylistAccount: { value: input.denylistAccount ?? null, isWritable: true },
        systemProgram: { value: input.systemProgram ?? 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.systemProgram.value) {
        accounts.systemProgram.value =
            '11111111111111111111111111111111';
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.payer),
            getAccountMeta(accounts.denylister),
            getAccountMeta(accounts.tokenMessenger),
            getAccountMeta(accounts.denylistAccount),
            getAccountMeta(accounts.systemProgram),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getUndenylistAccountInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseUndenylistAccountInstruction(instruction) {
    if (instruction.accounts.length < 7) {
        // 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: {
            payer: getNextAccount(),
            denylister: getNextAccount(),
            tokenMessenger: getNextAccount(),
            denylistAccount: getNextAccount(),
            systemProgram: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getUndenylistAccountInstructionDataDecoder().decode(instruction.data),
    };
}
