// iam 模块（B8 裁决：按 DEV_MODE 选择 mock 或 gRPC 实现）
import { Module } from "@nestjs/common";
import { env } from "../../config/env.js";
import { logger } from "../../shared/observability/logger.js";
import { IAM_CLIENT } from "./iam-client.interface.js";
import { IamGrpcClient } from "./iam-grpc.client.js";
import { IamMockClient } from "./iam-mock.client.js";

@Module({
  providers: [
    {
      provide: IAM_CLIENT,
      useFactory: () => {
        if (env.TEACHER_BFF_DEV_MODE) {
          logger.warn(
            { devMode: true },
            "IamClient using mock (TEACHER_BFF_DEV_MODE=true)",
          );
          return new IamMockClient();
        }
        logger.info(
          { devMode: false, target: env.IAM_GRPC_TARGET },
          "IamClient using gRPC",
        );
        return new IamGrpcClient();
      },
    },
  ],
  exports: [IAM_CLIENT],
})
export class IamModule {}
