import { Injectable, signal } from '@angular/core';
import { FeatureFlagsConfig, LocalizationConfig, PermissionsConfig } from '../../shared/models/config';

@Injectable({ providedIn: 'root' })
export class PlatformRuntimeStateService {
  private readonly initializedState = signal(false);
  private readonly localizationState = signal<LocalizationConfig | null>(null);
  private readonly featureFlagsState = signal<FeatureFlagsConfig | null>(null);
  private readonly permissionsState = signal<PermissionsConfig | null>(null);

  readonly initialized = this.initializedState.asReadonly();
  readonly localization = this.localizationState.asReadonly();
  readonly featureFlags = this.featureFlagsState.asReadonly();
  readonly permissions = this.permissionsState.asReadonly();

  markInitialized(next: {
    localization: LocalizationConfig;
    featureFlags: FeatureFlagsConfig;
    permissions: PermissionsConfig;
  }): void {
    this.localizationState.set(next.localization);
    this.featureFlagsState.set(next.featureFlags);
    this.permissionsState.set(next.permissions);
    this.initializedState.set(true);
  }
}
