import {
  IsInt,
  IsNotEmpty,
  IsObject,
  IsOptional,
  IsString,
  MaxLength,
  Min,
} from 'class-validator';

/**
 * Strokes are stored as vectors (section 13) so a drawing stays editable and
 * can be re-rendered at any resolution. `previewImagePath` is optional and
 * derived - it is never the source of truth.
 */
export class SaveDrawingDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  anonymousSessionId!: string;

  @IsOptional()
  @IsInt()
  activityId?: number;

  @IsOptional()
  @IsInt()
  templateId?: number;

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

  @IsOptional()
  @IsInt()
  @Min(1)
  canvasWidth?: number;

  @IsOptional()
  @IsInt()
  @Min(1)
  canvasHeight?: number;

  @IsObject()
  strokesJson!: Record<string, any>;

  @IsOptional()
  @IsString()
  @MaxLength(1024)
  previewImagePath?: string;
}

export class UpdateDrawingDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  anonymousSessionId!: string;

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

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

  @IsOptional()
  @IsInt()
  @Min(1)
  canvasWidth?: number;

  @IsOptional()
  @IsInt()
  @Min(1)
  canvasHeight?: number;

  @IsOptional()
  @IsString()
  @MaxLength(1024)
  previewImagePath?: string;
}
