"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.SET_CURRENT_TIME_DISCRIMINATOR = void 0;
exports.getSetCurrentTimeDiscriminatorBytes = getSetCurrentTimeDiscriminatorBytes;
exports.getSetCurrentTimeInstructionDataEncoder = getSetCurrentTimeInstructionDataEncoder;
exports.getSetCurrentTimeInstructionDataDecoder = getSetCurrentTimeInstructionDataDecoder;
exports.getSetCurrentTimeInstructionDataCodec = getSetCurrentTimeInstructionDataCodec;
exports.getSetCurrentTimeInstructionAsync = getSetCurrentTimeInstructionAsync;
exports.getSetCurrentTimeInstruction = getSetCurrentTimeInstruction;
exports.parseSetCurrentTimeInstruction = parseSetCurrentTimeInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.SET_CURRENT_TIME_DISCRIMINATOR = new Uint8Array([
    69, 100, 169, 193, 125, 0, 150, 69,
]);
function getSetCurrentTimeDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SET_CURRENT_TIME_DISCRIMINATOR);
}
function getSetCurrentTimeInstructionDataEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ['newTime', (0, kit_1.getU64Encoder)()],
    ]), (value) => ({ ...value, discriminator: exports.SET_CURRENT_TIME_DISCRIMINATOR }));
}
function getSetCurrentTimeInstructionDataDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ['newTime', (0, kit_1.getU64Decoder)()],
    ]);
}
function getSetCurrentTimeInstructionDataCodec() {
    return (0, kit_1.combineCodec)(getSetCurrentTimeInstructionDataEncoder(), getSetCurrentTimeInstructionDataDecoder());
}
async function getSetCurrentTimeInstructionAsync(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        state: { value: input.state ?? null, isWritable: true },
        signer: { value: input.signer ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    // Resolve default values.
    if (!accounts.state.value) {
        accounts.state.value = await (0, kit_1.getProgramDerivedAddress)({
            programAddress,
            seeds: [
                (0, kit_1.getBytesEncoder)().encode(new Uint8Array([115, 116, 97, 116, 101])),
            ],
        });
    }
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [getAccountMeta(accounts.state), getAccountMeta(accounts.signer)],
        programAddress,
        data: getSetCurrentTimeInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function getSetCurrentTimeInstruction(input, config) {
    // Program address.
    const programAddress = config?.programAddress ?? programs_1.SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS;
    // Original accounts.
    const originalAccounts = {
        state: { value: input.state ?? null, isWritable: true },
        signer: { value: input.signer ?? null, isWritable: false },
    };
    const accounts = originalAccounts;
    // Original args.
    const args = { ...input };
    const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
    const instruction = {
        accounts: [getAccountMeta(accounts.state), getAccountMeta(accounts.signer)],
        programAddress,
        data: getSetCurrentTimeInstructionDataEncoder().encode(args),
    };
    return instruction;
}
function parseSetCurrentTimeInstruction(instruction) {
    if (instruction.accounts.length < 2) {
        // 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: {
            state: getNextAccount(),
            signer: getNextAccount(),
        },
        data: getSetCurrentTimeInstructionDataDecoder().decode(instruction.data),
    };
}
