/**
 * createOODAAgent — public factory with boot-time dependency validation.
 *
 * Plan v6 §3.7: strict deps validation at construction.
 * - `SDK_STRICT_DEPS=false`: legacy mode — warn only, do not throw.
 * - `SDK_STRICT_DEPS` absent or any other value: strict mode — throw `MissingDependencyError`.
 *
 * @public
 */

import { OODAAgentImpl } from "./agent.js";
import { MissingDependencyError } from "./errors.js";
import type { OODAAgent, OODAAgentConfig } from "./types.js";

export function createOODAAgent<
  TConfig = unknown,
  TObs = unknown,
  TOrient = unknown,
  TDecision = unknown,
  TAction = unknown,
  TFeedback = unknown
>(
  config: OODAAgentConfig<TConfig, TObs, TOrient, TDecision, TAction, TFeedback>
): OODAAgent {
  // 0.17: default=legacy (opt-in via SDK_STRICT_DEPS=true). 1.0: default=strict.
  const strict = process.env["SDK_STRICT_DEPS"] === "true";

  if (!config.deps) {
    if (strict) {
      throw new MissingDependencyError("llm");
    }
    // Legacy mode: warn only — will throw in SDK 1.0
    console.warn(
      "[agent-sdk] OODAAgentConfig.deps missing — legacy mode. Will throw in 1.0."
    );
  } else if (strict && !config.deps.llm) {
    throw new MissingDependencyError("llm");
  }

  return new OODAAgentImpl<
    TConfig,
    TObs,
    TOrient,
    TDecision,
    TAction,
    TFeedback
  >(config);
}
