import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsEnum, IsNotEmpty, IsString, IsArray, IsOptional } from 'class-validator';
import { HostType, SendTo } from 'common/enum/HostType.enum';

export class SubscribeDto {
  @ApiProperty({
    example: 'user@example.com',
    description: 'Email address to subscribe',
  })
  @IsEmail()
  @IsNotEmpty()
  email: string;

  @ApiProperty({
    enum: HostType,
    example: HostType.DFUK,
    description: 'Host type for subscription (CAN or DFUK)',
  })
  @IsEnum(HostType)
  @IsNotEmpty()
  host: HostType;
}

export class UnsubscribeDto {
  @ApiProperty({
    example: 'user@example.com',
    description: 'Email address to unsubscribe',
  })
  @IsEmail()
  @IsNotEmpty()
  email: string;

  @ApiProperty({
    enum: HostType,
    example: HostType.DFUK,
    description: 'Host type to unsubscribe from',
  })
  @IsEnum(HostType)
  @IsNotEmpty()
  host: HostType;
}

export class SendNewsletterDto {
  @ApiProperty({
    example: 'Monthly Newsletter',
    description: 'Subject line of the newsletter',
  })
  @IsString()
  @IsNotEmpty()
  subject: string;

  @ApiProperty({
    example: '<h1>Newsletter Content</h1><p>Hello subscribers!</p>',
    description: 'HTML content of the newsletter',
  })
  @IsString()
  @IsNotEmpty()
  body: string;

  @ApiProperty({
    enum: SendTo,
    example: SendTo.ALL,
    description: 'Target audience for the newsletter',
  })
  @IsEnum(SendTo)
  @IsNotEmpty()
  sendTo: SendTo;

  @ApiProperty({
    example: ['user1@example.com', 'user2@example.com'],
    description: 'Custom email list (required only when sendTo is CUSTOM)',
    required: false,
    type: [String],
  })
  @IsArray()
  @IsEmail({}, { each: true })
  @IsOptional()
  customEmails?: string[];
}
