import { SimpleLocalClient } from '../../core/index.js';
import { EdimaxMapper } from './edimax.mapper.js';
import type { IEdimaxConfig, IEdimaxSnapshot } from './edimax.types.js';
import { edimaxProfile } from './edimax.types.js';

export class EdimaxClient extends SimpleLocalClient<IEdimaxConfig> {
  constructor(private readonly configArg: IEdimaxConfig) {
    super(edimaxProfile, configArg);
  }

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

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