import "reflect-metadata";
import { injectable } from "inversify";
import {
  NoopTracer,
  NoopLogger,
  type ITracer,
  type ILogger,
} from "@repo/core-shared/instrumentation";

import type { I{{pascalCase entity}}Repository } from "../../application/repositories/{{kebabCase entity}}.repository.interface";
import type { {{pascalCase entity}} } from "../../entities/models/{{kebabCase entity}}";

const DEFAULT_DATA = new Map<string, {{pascalCase entity}}>([
  ["seed-1", { id: "seed-1", name: "Seed One" }],
  ["seed-2", { id: "seed-2", name: "Seed Two" }],
]);

@injectable()
export class Mock{{pascalCase entity}}Repository implements I{{pascalCase entity}}Repository {
  private readonly data: Map<string, {{pascalCase entity}}>;
  private tracer: ITracer;
  private logger: ILogger;

  constructor(
    initialData?: Map<string, {{pascalCase entity}}>,
    tracer: ITracer = new NoopTracer(),
    logger: ILogger = new NoopLogger(),
  ) {
    this.data = initialData ?? new Map(DEFAULT_DATA);
    this.tracer = tracer;
    this.logger = logger;
    void this.logger; // currently unused; reserved for future mock-thrown captures
  }

  async get{{pascalCase entity}}(id: string): Promise<{{pascalCase entity}} | null> {
    return this.tracer.startSpan(
      { name: "{{camelCase entity}}.get{{pascalCase entity}}", op: "repository", attributes: {} },
      async (span) => {
        const found = this.data.get(id) ?? null;
        span.setAttribute("found", found !== null);
        return found;
      },
    );
  }
}
