// Custom type declarations to solve compatibility issues between baileys and @whiskeysockets/baileys

import { AuthenticationCreds, SignalDataTypeMap, SignalKeyStore } from 'baileys';

// Extend the baileys module to make it more compatible with @whiskeysockets/baileys
declare module 'baileys' {
  // Make the SignalKeyStore more permissive
  interface SignalKeyStore {
    get: <T extends keyof SignalDataTypeMap>(
      type: T,
      ids: string[]
    ) => Promise<{ [id: string]: SignalDataTypeMap[T] }> | { [id: string]: SignalDataTypeMap[T] };
    
    set: (data: any) => Promise<void> | void;
  }

  // Add any missing properties that might exist in @whiskeysockets/baileys
  interface BaileysEventEmitter {
    process?: (handler: (events: any) => void | Promise<void>) => () => void;
    buffer?: () => void;
    createBufferedFunction?: <A extends any[], T>(work: (...args: A) => Promise<T>) => (...args: A) => Promise<T>;
    flush?: (force?: boolean) => boolean;
    isBuffering?: () => boolean;
  }
}

// Ensure the WASocket type is compatible with both libraries
declare global {
  namespace NodeJS {
    interface ProcessEnv {
      PORT?: string;
      ENABLE_WEBHOOK?: string;
      DATABASE_URL?: string;
      BOT_NAME?: string;
      SESSION_CONFIG_ID?: string;
      MAX_RECONNECT_RETRIES?: string;
      SSE_MAX_QR_GENERATION?: string;
    }
  }
}

export {};
