import { SimpleLocalClient } from '../../core/index.js';
import { GoogleWifiMapper } from './google_wifi.mapper.js';
import type { IGoogleWifiConfig, IGoogleWifiSnapshot } from './google_wifi.types.js';
import { googleWifiProfile } from './google_wifi.types.js';

export class GoogleWifiClient extends SimpleLocalClient<IGoogleWifiConfig> {
  constructor(private readonly configArg: IGoogleWifiConfig) {
    super(googleWifiProfile, configArg);
  }

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