import {
  IsString,
  IsEnum,
  IsOptional,
  IsBoolean,
  IsObject,
  IsArray,
  MaxLength,
  IsNotEmpty,
  IsEmail,
  ArrayMaxSize,
} from 'class-validator';
import { Transform } from 'class-transformer';
import { FeedbackType, FeedbackSentiment } from '../feedback.entity';

export class CreateFeedbackDto {
  @IsEnum(FeedbackType, { message: 'Invalid feedback type' })
  type: FeedbackType;

  @IsString()
  @IsNotEmpty({ message: 'Message cannot be empty' })
  @MaxLength(5000, { message: 'Message cannot exceed 5000 characters' })
  @Transform(({ value }) => value?.trim())
  message: string;

  @IsString()
  @IsOptional()
  @MaxLength(200)
  title?: string;

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

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

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

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

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

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

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

  @IsArray()
  @IsOptional()
  @ArrayMaxSize(10, { message: 'Cannot have more than 10 tags' })
  tags?: string[];

  @IsString()
  @IsOptional()
  @IsEmail({}, { message: 'Invalid email format' })
  userEmail?: string;

  @IsBoolean()
  @IsOptional()
  contactAllowed?: boolean;

  @IsEnum(FeedbackSentiment)
  @IsOptional()
  sentiment?: FeedbackSentiment;
}
