import {
  IsBoolean,
  IsEnum,
  IsNotEmpty,
  IsString,
  IsUrl,
  MinLength,
} from 'class-validator';

const taskStatusEnum = {
  enabled: 'enabled',
  disabled: 'disabled',
} as const;

const executorEnum = {
  browser: 'browser',
  'agent-s': 'agent-s',
} as const;

export class CreateTaskDto {
  @IsString()
  @MinLength(2)
  name!: string;

  @IsUrl({ require_tld: false })
  siteUrl!: string;

  @IsString()
  @IsNotEmpty()
  cronExpr!: string;

  @IsString()
  @IsNotEmpty()
  serviceKey!: string;

  @IsEnum(executorEnum)
  preferredExecutor!: 'browser' | 'agent-s';

  @IsBoolean()
  allowAgentFallback!: boolean;

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

export class UpdateTaskDto extends CreateTaskDto {}

export class UpdateTaskStatusDto {
  @IsEnum(taskStatusEnum)
  status!: 'enabled' | 'disabled';
}
