import {
  IsBoolean,
  IsMongoId,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  Matches,
  Min,
} from "class-validator";

/**
 * Records progress for a single day. Which fields are required depends on the
 * challenge mode (enforced in the service against the joined challenge):
 *   HABIT       -> completed
 *   PERFORMANCE -> reps OR duration
 *   VOLUME      -> reps + weight, OR duration
 */
export class MarkChallengeDayDto {
  @IsMongoId()
  @IsNotEmpty()
  challenge_id: string;

  /**
   * Date only, no time — one calendar day == one entry.
   * Not used by HABIT: those windows roll from the exact start instant and a
   * closed window can never be back-filled, so the completion is always "now".
   */
  @IsOptional()
  @Matches(/^\d{4}-\d{2}-\d{2}$/, { message: "date must be YYYY-MM-DD" })
  date?: string;

  // HABIT
  @IsOptional()
  @IsBoolean()
  completed?: boolean;

  // PERFORMANCE + VOLUME
  @IsOptional()
  @IsNumber()
  @Min(0)
  reps?: number;

  // VOLUME (kg)
  @IsOptional()
  @IsNumber()
  @Min(0)
  weight?: number;

  // PERFORMANCE + VOLUME time-based moves (seconds)
  @IsOptional()
  @IsNumber()
  @Min(0)
  duration?: number;
}
