import { IsString, IsNotEmpty, Matches, IsOptional, IsBoolean } from "class-validator";

export class CreateCronDto {
  @IsString()
  @IsNotEmpty()
  expression!: string;

  @IsString()
  @IsNotEmpty()
  command!: string;
}

// Cron validation regex
// eslint-disable-next-line security/detect-unsafe-regex
const CRON_VALIDATION_REGEX = /^(\*|[0-5]?[0-9])(\s+(\*|[0-5]?[0-9])){4}$/;

export class UpdateCronDto {
  @IsString()
  @IsOptional()
  @Matches(CRON_VALIDATION_REGEX, {
    message: "Invalid cron expression",
  })
  expression?: string;

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

  @IsBoolean()
  @IsOptional()
  enabled?: boolean;
}
