import { IsString, IsEnum, IsOptional, IsObject, Matches } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export enum TaskType {
  RESTART = 'restart',
  ANNOUNCEMENT = 'announcement',
  COMMAND = 'command',
  PLUGIN_RELOAD = 'plugin_reload',
}

export class CreateTaskDto {
  @ApiProperty({
    description: 'Type of scheduled task',
    enum: TaskType,
    example: 'restart',
  })
  @IsEnum(TaskType)
  task_type: TaskType;

  @ApiProperty({
    description: 'Name of the task',
    example: 'Daily restart',
  })
  @IsString()
  task_name: string;

  @ApiProperty({
    description: 'Cron expression (e.g., "0 0 * * *" for daily at midnight)',
    example: '0 0 * * *',
  })
  @IsString()
  @Matches(/^(\*|([0-5]?\d)) (\*|([01]?\d|2[0-3])) (\*|([01]?\d|2\d|3[01])) (\*|([0]?\d|1[0-2])) (\*|[0-6])$/, {
    message: 'Invalid cron expression format',
  })
  cron_expression: string;

  @ApiProperty({
    description: 'Timezone for the schedule (IANA timezone)',
    example: 'America/New_York',
    required: false,
  })
  @IsString()
  @IsOptional()
  timezone?: string;

  @ApiProperty({
    description: 'Task-specific configuration object',
    example: { message: 'Server restarting in 5 minutes', countdown: 300 },
    required: false,
  })
  @IsObject()
  @IsOptional()
  task_config?: Record<string, any>;
}
