import { SimpleLocalClient } from '../../core/index.js';
import { Gogogate2Mapper } from './gogogate2.mapper.js';
import type { IGogogate2Config, IGogogate2Snapshot } from './gogogate2.types.js';
import { gogogate2Profile } from './gogogate2.types.js';

export class Gogogate2Client extends SimpleLocalClient<IGogogate2Config> {
  constructor(private readonly configArg: IGogogate2Config) {
    super(gogogate2Profile, configArg);
  }

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