import { SimpleLocalClient } from '../../core/index.js';
import { HdfuryMapper } from './hdfury.mapper.js';
import type { IHdfuryConfig, IHdfurySnapshot } from './hdfury.types.js';
import { hdfuryProfile } from './hdfury.types.js';

export class HdfuryClient extends SimpleLocalClient<IHdfuryConfig> {
  constructor(private readonly configArg: IHdfuryConfig) {
    super(hdfuryProfile, configArg);
  }

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

    return HdfuryMapper.toSnapshot({ config: this.configArg, rawData: snapshot.rawData, online: snapshot.online, source: snapshot.source, error: snapshot.error });
  }
}
