import { Injectable, Logger } from '@nestjs/common';
import { EmailVerificationType } from '../../domain/entities/email-verification.entity';
import { IEmailProvider, EmailDeliveryResult } from './email-provider.interface';

/**
 * Console Email Provider (开发/测试模式)
 *
 * EMAIL_ENABLED=false 时启用，将验证码打印到控制台而非真实发送。
 */
@Injectable()
export class ConsoleEmailProvider implements IEmailProvider {
  private readonly logger = new Logger('ConsoleEmailProvider');

  async send(
    email: string,
    code: string,
    type: EmailVerificationType,
  ): Promise<EmailDeliveryResult> {
    this.logger.warn(
      `[DEV] Email code [${type}] → ${email} : ${code}`,
    );
    return { success: true, providerId: `console-${Date.now()}` };
  }
}
