import { Readable } from 'stream';
import { BaseConnection, Close } from './baseConnection.types.cjs';
import { Ifs } from './ifs/types.cjs';

interface ProgramDefinitionOptions {
    programName: string;
    paramsSchema: PgmParamType[];
    libraryName?: string;
    ccsid?: number;
}
interface PgmParamType1 {
    name: string;
    size: number;
    type?: string;
    decimals?: number;
}
interface PgmParamType2 {
    name: string;
    precision: number;
    typeName?: string;
    scale?: number;
}
interface PgmParamStructType {
    [key: string]: PgmParamType[];
}
type PgmParamType = PgmParamType1 | PgmParamType2 | PgmParamStructType;
interface JustNameMessageQ {
    name: string;
}
interface JustPathMessageQ {
    path: string;
}
type MessageQOptions = JustNameMessageQ | JustPathMessageQ;
interface MessageQReadOptions {
    wait?: number;
}
interface DataQReadOptions {
    key: string;
    wait?: number;
    writeKeyLength?: number;
}
interface MessageFileHandlerOptions {
    path: string;
}
interface MessageFileReadOptions {
    messageId: string[7];
}
interface MessageQ {
    sendInformational: (messageText: string) => Promise<void>;
    read: (params?: MessageQReadOptions) => Promise<any> | Promise<null>;
}
interface DataQOptions {
    name: string;
}
interface KeyedDataQ {
    write: (key: string, data: string) => void;
    read: (params: DataQReadOptions | string) => Promise<any>;
}
interface AS400Message {
    getText: () => Promise<string>;
}
interface MessageFileHandler {
    read: (params: MessageFileReadOptions) => Promise<AS400Message>;
}
type TransactionFun = (transaction: BaseConnection) => Promise<any>;
interface Connection extends BaseConnection {
    pgm: (programName: string, paramsSchema: PgmParamType[], libraryName?: string) => any;
    defineProgram: (options: ProgramDefinitionOptions) => any;
    getTablesAsStream: (params: any) => Readable;
    getColumns: (params: any) => any;
    getPrimaryKeys: (params: any) => any;
    transaction: (fn: TransactionFun) => Promise<any>;
    openMessageQ: (params: MessageQOptions) => Promise<MessageQ>;
    createKeyedDataQ: (params: DataQOptions) => KeyedDataQ;
    openMessageFile: (params: MessageFileHandlerOptions) => Promise<MessageFileHandler>;
    ifs: () => Ifs;
    close: Close;
}

export type { AS400Message, Connection, DataQOptions, DataQReadOptions, JustNameMessageQ, JustPathMessageQ, KeyedDataQ, MessageFileHandler, MessageFileHandlerOptions, MessageFileReadOptions, MessageQ, MessageQOptions, MessageQReadOptions, PgmParamStructType, PgmParamType, PgmParamType1, PgmParamType2, ProgramDefinitionOptions, TransactionFun };
