import { Injectable, computed, inject } from '@angular/core';
import { SCHOLING_THRESHOLD_DEFAULT } from '../domain/intake.machine';
import { IntakePolicyAdapter } from '../infrastructure/intake-policy.adapter';

/**
 * Application-layer facade for the server-owned intake policy (the scholing
 * threshold config value). It owns the httpResource (created here, in the required
 * injection context) and exposes the threshold as a derived signal, falling back to
 * the domain default until the backend answers. The UI reaches the network through
 * application/, never infrastructure/ directly (CLAUDE.md §1). The backend stays the
 * authority and re-validates on submit.
 */
@Injectable({ providedIn: 'root' })
export class IntakePolicyStore {
  private policy = inject(IntakePolicyAdapter);
  private policyRes = this.policy.policyResource();

  readonly scholingThreshold = computed(
    () => this.policyRes.value()?.scholingThreshold ?? SCHOLING_THRESHOLD_DEFAULT,
  );
}
