import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {
  BehaviorSubject,
  filter,
  map,
  Observable,
  of,
  switchMap,
  take,
  tap,
  throwError,
} from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class EvoService {
  // Private
  private __evoSetting = new BehaviorSubject<any | undefined>(undefined);

  /**
   * Constructor
   */
  constructor(private _httpClient: HttpClient) {}

  // -----------------------------------------------------------------------------------------------------
  // @ Accessors
  // -----------------------------------------------------------------------------------------------------

  /**
   * Getter for game
   */
  get evoSetting$(): Observable<any | undefined> {
    return this.__evoSetting.asObservable();
  }

  // -----------------------------------------------------------------------------------------------------
  // @ Public methods
  // -----------------------------------------------------------------------------------------------------

  /**
   * Get powerballs
   *
   *
   */
  getEvoSetting(): Observable<{
    evoSetting: any;
  }> {
    return this._httpClient
      .get<{ evoSetting: any }>('api/apps/settings/evo')
      .pipe(
        tap((response) => {
          this.__evoSetting.next(response.evoSetting);
        })
      );
  }
}
