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 GameService {
  // Private
  private __gameSetting = new BehaviorSubject<any | undefined>(undefined);

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

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

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

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

  /**
   * Get powerballs
   *
   *
   */
  getGameSetting(): Observable<{
    gameSetting: any;
  }> {
    return this._httpClient
      .get<{ gameSetting: any }>('api/apps/settings/game')
      .pipe(
        tap((response) => {
          this.__gameSetting.next(response.gameSetting);
        })
      );
  }
}
