import { HttpClient } from '@angular/common/http';
import { Injectable, inject, signal } from '@angular/core';
import { Observable, tap } from 'rxjs';
import { TenantContext } from '../../models/context/context.model';

@Injectable({ providedIn: 'root' })
export class TenantContextService {
  private readonly http = inject(HttpClient);
  readonly tenantContext = signal<TenantContext | null>(null);

  loadTenantContext(): Observable<TenantContext> {
    return this.http.get<TenantContext>(``).pipe(
      tap((context) => {
        this.tenantContext.set(context);
      })
    );
  }

  clear(): void {
    this.tenantContext.set(null);
  }
}