

import 'package:oto/oto/commands/command.dart';
import 'package:oto/oto/data/command_data.dart';

class Delay extends Command {
  Function? get error => null;

  @override
  Future execute(DataCommand command) async {
    var data = DataDelay.fromJson(getParam(command));

    if(data.millisecond != null) {
      print('Delay: ${data.millisecond} millisecond');
      await Future.delayed(Duration(milliseconds: data.millisecond!));
    }
    
    if(data.second != null) {
      print('Delay: ${data.second} second');
      await Future.delayed(Duration(seconds: data.second!));
    }

    if(data.minute != null) {
      print('Delay: ${data.minute} minute');
      await Future.delayed(Duration(minutes: data.minute!));
    }

    if(data.hour != null) {
      print('Delay: ${data.hour} hour');
      await Future.delayed(Duration(hours: data.hour!));
    }

    return await complete(0, command);
  }
}
void registerTimerCommand() {
  Command.register(
    CommandType.Delay,
    () => Delay(),
    spec: const CommandSpec(
      type: CommandType.Delay,
      category: 'util',
      dataModel: 'DataDelay',
      samplePath: 'assets/yaml/sample/11_utils.yaml',
    ),
  );
}
