import { ArrayNotEmpty, IsArray, IsBoolean, IsIn, IsOptional, IsString, MinLength } from 'class-validator';

export class CreateChatRoomDto {
  @IsString()
  @MinLength(1)
  name!: string;

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

export class CreateE2EChatRoomDto {
  @IsString()
  peerUserId!: string;
}

export class UpdateChatRoomDto {
  @IsOptional()
  @IsString()
  @MinLength(1)
  name?: string;

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

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

export class SendChatMessageDto {
  @IsString()
  @IsIn(['TEXT', 'IMAGE', 'AUDIO', 'VOICE', 'FILE', 'EMOJI', 'POLL'])
  type!: string;

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

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

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

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

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

  @IsOptional()
  poll?: {
    question: string;
    options: string[];
    allowsMultiple?: boolean;
    isAnonymous?: boolean;
  };

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

export class VotePollDto {
  @IsArray()
  @IsString({ each: true })
  optionIds!: string[];
}

export class SetRoomNotificationsMutedDto {
  @IsBoolean()
  muted!: boolean;
}

export class AddChatRoomMemberDto {
  @IsString()
  memberUserId!: string;
}

export class EditChatMessageDto {
  @IsString()
  @MinLength(1)
  content!: string;
}

export class MarkRoomReadDto {
  @IsOptional()
  @IsString()
  lastMessageId?: string;
}

export class ToggleMessageReactionDto {
  @IsString()
  @MinLength(1)
  emoji!: string;
}

export class SetMessagePinnedDto {
  @IsBoolean()
  pinned!: boolean;
}

export class ForwardMessagesDto {
  @IsArray()
  @ArrayNotEmpty()
  @IsString({ each: true })
  messageIds!: string[];
}
