import {
  IsString,
  IsOptional,
  IsEnum,
  IsUUID,
  IsDateString,
  MaxLength,
  ValidateIf,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export enum ActivityType {
  NOTE = 'NOTE',
  CALL = 'CALL',
  EMAIL = 'EMAIL',
  MEETING = 'MEETING',
  TASK = 'TASK',
}

export class CreateActivityDto {
  @ApiPropertyOptional({ format: 'uuid', description: 'Kontakt-ID (optional wenn companyId gesetzt)' })
  @IsOptional()
  @ValidateIf((o) => !o.companyId)
  @IsUUID()
  contactId?: string;

  @ApiPropertyOptional({ format: 'uuid', description: 'Unternehmens-ID (optional wenn contactId gesetzt)' })
  @IsOptional()
  @ValidateIf((o) => !o.contactId)
  @IsUUID()
  companyId?: string;

  @ApiProperty({ enum: ActivityType })
  @IsEnum(ActivityType)
  type!: ActivityType;

  @ApiProperty({ maxLength: 500 })
  @IsString()
  @MaxLength(500)
  subject!: string;

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

  @ApiPropertyOptional({ format: 'date-time' })
  @IsOptional()
  @IsDateString()
  scheduledAt?: string;

  @ApiPropertyOptional({ format: 'date-time' })
  @IsOptional()
  @IsDateString()
  completedAt?: string;
}
