import { SimpleLocalClient } from '../../core/index.js';
import { Edl21Mapper } from './edl21.mapper.js';
import type { IEdl21Config, IEdl21Snapshot } from './edl21.types.js';
import { edl21Profile } from './edl21.types.js';

export class Edl21Client extends SimpleLocalClient<IEdl21Config> {
  constructor(private readonly configArg: IEdl21Config) {
    super(edl21Profile, configArg);
  }

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

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