import { describe, it, expect } from "bun:test";
import { Effect, Layer } from "effect";

describe("Self-Improvement — Builder API", () => {
  it("withSelfImprovement() method exists and is chainable", async () => {
    const { ReactiveAgents } = await import("../src/builder.js");
    const builder = ReactiveAgents.create()
      .withName("test-agent")
      .withProvider("test")
      .withModel("test-model")
      .withSelfImprovement()
      .withReasoning()
      .withMemory("2");

    // Builder should be chainable — no errors
    expect(builder).toBeDefined();
  });

  it("enableSelfImprovement is included in config schema", async () => {
    const { ReactiveAgentsConfigSchema } = await import("../src/types.js");
    // The schema should accept enableSelfImprovement
    const { Schema } = await import("effect");
    const decode = Schema.decodeSync(ReactiveAgentsConfigSchema);
    const config = decode({
      maxIterations: 10,
      memoryTier: "2",
      enableGuardrails: false,
      enableVerification: false,
      enableCostTracking: false,
      enableAudit: false,
      agentId: "test",
      enableSelfImprovement: true,
    });
    expect(config.enableSelfImprovement).toBe(true);
  });
});

describe("Self-Improvement — Adaptive Strategy Experience", () => {
  it("buildAnalysisPrompt includes past experience when provided", async () => {
    const { executeAdaptive } = await import("@reactive-agents/reasoning");
    expect(executeAdaptive).toBeDefined();

    // Verify the StrategyOutcome type is exported from reasoning
    const reasoning = await import("@reactive-agents/reasoning");
    // Type check: StrategyOutcome type should be importable
    type SO = typeof reasoning extends { StrategyOutcome: infer T } ? T : never;
    // The export exists at runtime as a type — not directly testable,
    // but we can verify the adaptive function accepts the input shape
    expect(typeof executeAdaptive).toBe("function");
  });
});
