import { Injectable, Inject } from "@nestjs/common";
import type { IamClient } from "../clients/iam.client.js";
import type { CoreEduClient } from "../clients/core-edu.client.js";
import type { Loaders } from "./loaders.js";
import { createLoaders } from "./loaders.js";

/**
 * DataLoader 工厂（对齐 02-architecture-design.md §6.3）。
 *
 * 每次请求调用 createLoaders() 生成独立的 DataLoader 实例集合。
 * Resolver 通过 GraphQL context.loaders 访问。
 */
@Injectable()
export class DataLoaderFactory {
  private readonly iamClient: IamClient;
  private readonly coreEduClient: CoreEduClient;

  constructor(
    @Inject("IAM_CLIENT") iamClient: IamClient,
    @Inject("CORE_EDU_CLIENT") coreEduClient: CoreEduClient,
  ) {
    this.iamClient = iamClient;
    this.coreEduClient = coreEduClient;
  }

  createLoaders(): Loaders {
    return createLoaders(this.iamClient, this.coreEduClient);
  }
}
