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

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

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

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

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

  /**
   * Get powerballs
   *
   *
   */
  getDomainSetting(): Observable<{
    domainSetting: any;
  }> {
    return this._httpClient
      .get<{ domainSetting: any }>('api/apps/settings/domain')
      .pipe(
        tap((response) => {
          this.__domainSetting.next(response.domainSetting);
        })
      );
  }
}
