import {
  IsArray,
  IsMongoId,
  IsNumber,
  IsObject,
  IsOptional,
  IsString,
  ValidateNested,
} from "class-validator";
import { Type } from "class-transformer";

export class TrainingSetDto {
  // Dynamic numeric values keyed by the exercise category's field keys.
  // e.g. { reps: 12, weight: 20, break_duration: 60 } or { duration: 60, break_duration: 30 }
  @IsObject()
  values: Record<string, number>;
}

export class PlanExerciseDto {
  @IsMongoId()
  exercise_id: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => TrainingSetDto)
  sets: TrainingSetDto[];
}

export class PlanDayDto {
  @IsObject()
  name: Record<string, string>;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => PlanExerciseDto)
  exercises: PlanExerciseDto[];
}

export class CreateTrainingPlanDto {
  @IsObject()
  name: Record<string, string>;

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

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

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => PlanDayDto)
  days: PlanDayDto[];

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

  @IsOptional()
  @IsNumber()
  status?: number;
}
