import { SimpleLocalClient } from '../../core/index.js';
import { FluxLedMapper } from './flux_led.mapper.js';
import type { IFluxLedConfig, IFluxLedSnapshot } from './flux_led.types.js';
import { fluxLedProfile } from './flux_led.types.js';

export class FluxLedClient extends SimpleLocalClient<IFluxLedConfig> {
  constructor(private readonly configArg: IFluxLedConfig) {
    super(fluxLedProfile, configArg);
  }

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

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