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

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

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

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

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

  /**
   * Get powerballs
   *
   *
   */
  getBranchSetting(): Observable<{
    branchSetting: any;
  }> {
    return this._httpClient
      .get<{ branchSetting: any }>('api/apps/settings/branch')
      .pipe(
        tap((response) => {
          this.__branchSetting.next(response.branchSetting);
        })
      );
  }
}
