import { logger } from "../shared/observability/logger.js";
import type {
  ChannelSendContext,
  ChannelSendResult,
  NotificationChannelStrategy,
} from "./channel.types.js";

/**
 * EmailChannel —— 邮件渠道（P5 stub）。
 *
 * P5 阶段无实际 SMTP 网关，仅记录投递意图。
 * 后续接入 SMTP 服务时替换 send 实现，接口不变（策略模式扩展点）。
 *
 * 仲裁依据 02-architecture-design.md §2.4：软失败，不阻断主流程。
 */
class EmailChannel implements NotificationChannelStrategy {
  readonly name = "email" as const;

  async send(ctx: ChannelSendContext): Promise<ChannelSendResult> {
    // P5 stub：记录投递意图，不实际发送
    logger.info(
      { userId: ctx.userId, notificationId: ctx.notificationId },
      "Email channel stub: delivery intent logged (SMTP not configured)",
    );
    return {
      channel: "email",
      sent: false,
      error: "SMTP gateway not configured (P5 stub)",
    };
  }
}

export const emailChannel = new EmailChannel();
