import { Transport, type MicroserviceOptions } from "@nestjs/microservices";
import { resolve } from "node:path";
import { env } from "./env.js";

/**
 * gRPC 微服务配置。
 *
 * 仲裁依据 M1：gRPC 50056 启用，对齐 msg.proto package next_edu_cloud.msg.v1。
 *
 * proto 文件路径解析：
 * - 开发环境：从 services/msg/ 出发，../../packages/shared-proto/proto/msg.proto
 * - 生产环境：Docker 容器内保留 workspace 结构，同上路径
 */
const PROTO_PATH = resolve(
  process.cwd(),
  "..",
  "..",
  "packages",
  "shared-proto",
  "proto",
  "msg.proto",
);

export const grpcMicroserviceOptions: MicroserviceOptions = {
  transport: Transport.GRPC,
  options: {
    package: "next_edu_cloud.msg.v1",
    protoPath: PROTO_PATH,
    url: `0.0.0.0:${env.GRPC_PORT}`,
  },
};
