/**
 * 邮件配置策略
 */
import { NotificationChannelType, isEmailConfig } from '../../types';
import type { ConfigStrategy, ConfigState } from './types';

export class EmailConfigStrategy implements ConfigStrategy {
  type = NotificationChannelType.EMAIL;

  getDefaultConfig() {
    return {
      channelType: NotificationChannelType.EMAIL,
      smtpHost: '',
      smtpPort: 465,
      username: '',
      password: '',
      from: '',
      useSsl: true,
    };
  }

  validateConfig(config: any): boolean {
    return config && 
           config.channelType === NotificationChannelType.EMAIL && 
           typeof config.smtpHost === 'string' && 
           config.smtpHost.length > 0 &&
           typeof config.smtpPort === 'number' &&
           typeof config.username === 'string' && 
           config.username.length > 0;
  }

  loadFromData(data: any): ConfigState {
    // 邮件配置不再需要额外的状态管理
    return {};
  }

  buildConfig(state: ConfigState, formConfig: any): any {
    return {
      ...formConfig,
      channelType: NotificationChannelType.EMAIL,
    };
  }
}
