import { describe, it, expect } from "vitest";
import { RecordingTracer, RecordingLogger } from "@repo/core-testing/instrumentation";
import { stubPayloadConfig } from "@repo/core-testing/payload/stub-config";
import { {{pascalCase entity}}Repository } from "@/infrastructure/repositories/{{kebabCase entity}}.repository";

// Phase-1 scaffold: the real repository returns null until the Payload
// collection is wired. These tests pin the span shape and the stub return
// value so that callers (use case + DI tests) keep working when the body is
// later replaced with a real `payload.find()` call.

describe("{{pascalCase entity}}Repository (Phase-1 stub)", () => {
  it("returns null and emits a span with op='repository'", async () => {
    const tracer = new RecordingTracer();
    const logger = new RecordingLogger();
    const repo = new {{pascalCase entity}}Repository(stubPayloadConfig, tracer, logger);

    const result = await repo.get{{pascalCase entity}}("anything");

    expect(result).toBeNull();
    expect(tracer.spans).toHaveLength(1);
    expect(tracer.spans[0]).toMatchObject({
      name: "{{camelCase entity}}.get{{pascalCase entity}}",
      op: "repository",
    });
  });

  it("records the requested id as a span attribute", async () => {
    const tracer = new RecordingTracer();
    const repo = new {{pascalCase entity}}Repository(stubPayloadConfig, tracer);
    await repo.get{{pascalCase entity}}("custom-id");
    expect(tracer.spans[0]!.attributes.id).toBe("custom-id");
    expect(tracer.spans[0]!.attributes.found).toBe(false);
  });
});
