/* eslint-disable @typescript-eslint/no-explicit-any */

type DatabaseType = 'MySQL' | 'PostgreSQL' | 'MongoDB' | 'SQLite';
interface DatabaseConfigOptions {
  host: string;
  port: number;
  user: string;
  password: string;
  dbName: string;
  actions:any[];
  actionImplementionCode:any   
}

//datasource
class DatabaseConfig {
  private configurations: Map<DatabaseType, DatabaseConfigOptions>;
  constructor() {
    this.configurations = new Map();
  }
  public registerDatabase(type: DatabaseType, config: DatabaseConfigOptions): void {
    this.configurations.set(type, config);
  }
  public async connectToDatabase(type: DatabaseType): Promise<boolean|void> {
    const config = this.configurations.get(type);

    if (!config) {
      throw new Error(`Database configuration for ${type} not found.`);
    }
     //connection code if required
  }

  public async performDatabaseAction(
    type: DatabaseType,
    action: string,
     data?: any
  ): Promise<any> {
    const config = this.configurations.get(type);

    if (!config) {
      throw new Error(`Database configuration for ${type} not found.`);
    }
    // call implentation code and give actionType and data in actionImplementionCode
    config.actionImplementionCode(action,data)
  }

  public getDatabaseConfig(type: DatabaseType): DatabaseConfigOptions | undefined {
    return this.configurations.get(type);
  }
  public getAllDatabaseConfigs(): Map<DatabaseType, DatabaseConfigOptions> {
    return this.configurations;
  }
}

export default DatabaseConfig;