import { SimpleLocalClient } from '../../core/index.js';
import { GeniushubMapper } from './geniushub.mapper.js';
import type { IGeniushubConfig, IGeniushubSnapshot } from './geniushub.types.js';
import { geniushubProfile } from './geniushub.types.js';

export class GeniushubClient extends SimpleLocalClient<IGeniushubConfig> {
  constructor(private readonly configArg: IGeniushubConfig) {
    super(geniushubProfile, configArg);
  }

  public async getSnapshot(forceRefreshArg = false): Promise<IGeniushubSnapshot> {
    const snapshot = await super.getSnapshot(forceRefreshArg);
    if (snapshot.rawData === undefined && snapshot.entities.length) {
      return GeniushubMapper.toSnapshot({ config: { ...this.configArg, snapshot }, online: snapshot.online, source: snapshot.source, error: snapshot.error });
    }
    return GeniushubMapper.toSnapshot({ config: this.configArg, rawData: snapshot.rawData, online: snapshot.online, source: snapshot.source, error: snapshot.error });
  }
}
