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

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

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

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

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

  /**
   * Get powerballs
   *
   *
   */
  getLadderSetting(): Observable<{
    ladderSetting: any;
  }> {
    return this._httpClient
      .get<{ ladderSetting: any }>('api/apps/settings/ladder')
      .pipe(
        tap((response) => {
          this.__ladderSetting.next(response.ladderSetting);
        })
      );
  }
}
