"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.EMERGENCY_DELETE_ROOT_BUNDLE_DISCRIMINATOR = void 0;
exports.getEmergencyDeleteRootBundleDiscriminatorBytes = getEmergencyDeleteRootBundleDiscriminatorBytes;
exports.getEmergencyDeleteRootBundleInstructionDataEncoder = getEmergencyDeleteRootBundleInstructionDataEncoder;
exports.getEmergencyDeleteRootBundleInstructionDataDecoder = getEmergencyDeleteRootBundleInstructionDataDecoder;
exports.getEmergencyDeleteRootBundleInstructionDataCodec = getEmergencyDeleteRootBundleInstructionDataCodec;
exports.getEmergencyDeleteRootBundleInstructionAsync = getEmergencyDeleteRootBundleInstructionAsync;
exports.getEmergencyDeleteRootBundleInstruction = getEmergencyDeleteRootBundleInstruction;
exports.parseEmergencyDeleteRootBundleInstruction = parseEmergencyDeleteRootBundleInstruction;
const web3_v2_js_1 = require("@solana/web3-v2.js");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.EMERGENCY_DELETE_ROOT_BUNDLE_DISCRIMINATOR = new Uint8Array([
    226, 158, 1, 74, 84, 113, 24, 152,
]);
function getEmergencyDeleteRootBundleDiscriminatorBytes() {
    return (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 8).encode(exports.EMERGENCY_DELETE_ROOT_BUNDLE_DISCRIMINATOR);
}
function getEmergencyDeleteRootBundleInstructionDataEncoder() {
    return (0, web3_v2_js_1.transformEncoder)((0, web3_v2_js_1.getStructEncoder)([
        ['discriminator', (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 8)],
        ['rootBundleId', (0, web3_v2_js_1.getU32Encoder)()],
    ]), (value) => ({
        ...value,
        discriminator: exports.EMERGENCY_DELETE_ROOT_BUNDLE_DISCRIMINATOR,
    }));
}
function getEmergencyDeleteRootBundleInstructionDataDecoder() {
    return (0, web3_v2_js_1.getStructDecoder)([
        ['discriminator', (0, web3_v2_js_1.fixDecoderSize)((0, web3_v2_js_1.getBytesDecoder)(), 8)],
        ['rootBundleId', (0, web3_v2_js_1.getU32Decoder)()],
    ]);
}
function getEmergencyDeleteRootBundleInstructionDataCodec() {
    return (0, web3_v2_js_1.combineCodec)(getEmergencyDeleteRootBundleInstructionDataEncoder(), getEmergencyDeleteRootBundleInstructionDataDecoder());
}
async function getEmergencyDeleteRootBundleInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SVM_SPOKE_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        signer: { value: input.signer ?? null, isWritable: false },
        closer: { value: input.closer ?? null, isWritable: true },
        state: { value: input.state ?? null, isWritable: false },
        rootBundle: { value: input.rootBundle ?? null, isWritable: true },
        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.eventAuthority.value) {
        accounts.eventAuthority.value = await (0, web3_v2_js_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, web3_v2_js_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.signer),
            getAccountMeta(accounts.closer),
            getAccountMeta(accounts.state),
            getAccountMeta(accounts.rootBundle),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getEmergencyDeleteRootBundleInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function getEmergencyDeleteRootBundleInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SVM_SPOKE_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        signer: { value: input.signer ?? null, isWritable: false },
        closer: { value: input.closer ?? null, isWritable: true },
        state: { value: input.state ?? null, isWritable: false },
        rootBundle: { value: input.rootBundle ?? null, isWritable: true },
        eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
        program: { value: input.program ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [
            getAccountMeta(accounts.signer),
            getAccountMeta(accounts.closer),
            getAccountMeta(accounts.state),
            getAccountMeta(accounts.rootBundle),
            getAccountMeta(accounts.eventAuthority),
            getAccountMeta(accounts.program),
        ],
        programAddress,
        data: getEmergencyDeleteRootBundleInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseEmergencyDeleteRootBundleInstruction(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: {
            signer: getNextAccount(),
            closer: getNextAccount(),
            state: getNextAccount(),
            rootBundle: getNextAccount(),
            eventAuthority: getNextAccount(),
            program: getNextAccount(),
        },
        data: getEmergencyDeleteRootBundleInstructionDataDecoder().decode(instruction.data),
    };
}
