import { IsString, IsOptional, IsEnum, IsObject, IsArray, IsBoolean } from 'class-validator';
import { Type } from 'class-transformer';
import { NotificationChannel } from '@prisma/client';

export class SendNotificationDto {
  @IsEnum(NotificationChannel)
  channel: NotificationChannel;

  @IsString()
  to: string; // userId or email

  @IsOptional()
  @IsString()
  subject?: string;

  @IsOptional()
  @IsString()
  content?: string;

  @IsOptional()
  @IsString()
  templateCode?: string;

  @IsOptional()
  @IsObject()
  variables?: Record<string, any>;

  @IsOptional()
  @IsEnum(['HIGH', 'NORMAL', 'LOW'])
  priority?: 'HIGH' | 'NORMAL' | 'LOW';

  @IsOptional()
  @IsObject()
  metadata?: any;
}

export class SendBatchDto {
  @IsArray()
  @Type(() => SendNotificationDto)
  notifications: SendNotificationDto[];
}

export class CreateTemplateDto {
  @IsString()
  code: string;

  @IsString()
  name: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsEnum(NotificationChannel)
  channel: NotificationChannel;

  @IsOptional()
  @IsString()
  subject?: string;

  @IsString()
  template: string;

  @IsArray()
  @IsString({ each: true })
  variables: string[];

  @IsOptional()
  @IsObject()
  example?: any;

  @IsOptional()
  @IsEnum(['HIGH', 'NORMAL', 'LOW'])
  priority?: 'HIGH' | 'NORMAL' | 'LOW';
}

export class UpdateTemplateDto {
  @IsOptional()
  @IsString()
  name?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsString()
  subject?: string;

  @IsOptional()
  @IsString()
  template?: string;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  variables?: string[];

  @IsOptional()
  @IsObject()
  example?: any;

  @IsOptional()
  @IsEnum(['HIGH', 'NORMAL', 'LOW'])
  priority?: 'HIGH' | 'NORMAL' | 'LOW';

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;
}

export class TestRenderDto {
  @IsString()
  templateCode: string;

  @IsObject()
  variables: Record<string, any>;
}

export class QueryLogsDto {
  @IsOptional()
  @IsString()
  recipientId?: string;

  @IsOptional()
  @IsEnum(NotificationChannel)
  channel?: NotificationChannel;

  @IsOptional()
  @IsEnum(['PENDING', 'SENDING', 'SENT', 'FAILED', 'CANCELLED'])
  status?: string;

  @IsOptional()
  @IsString()
  startDate?: string;

  @IsOptional()
  @IsString()
  endDate?: string;

  @IsOptional()
  @Type(() => Number)
  page?: number;

  @IsOptional()
  @Type(() => Number)
  limit?: number;
}

