import { Type } from 'class-transformer';
import { ArrayMinSize, IsArray, IsInt, Min, ValidateNested } from 'class-validator';

export class ReorderItemDto {
  @IsInt()
  id!: number;

  @IsInt()
  @Min(0)
  orderIndex!: number;
}

/** Payload for the drag-and-drop reordering the admin panel performs. */
export class ReorderDto {
  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => ReorderItemDto)
  items!: ReorderItemDto[];
}
