// ignore_for_file: depend_on_referenced_packages

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

class DirectoryCreate extends Command {
  @override
  Future execute(DataCommand command) async {
    var data = DataDirectoryCreate.fromJson(getParam(command));
    var dir = Directory(data.path);
    if(!dir.existsSync()) {
      await dir.create(recursive: true);
      Application.log('Directory Created: ${data.path}');
    }
    return complete(0, command);
  }
}
void registerDirectoryCommand() {
  Command.register(
    CommandType.DirectoryCreate,
    () => DirectoryCreate(),
    spec: const CommandSpec(
      type: CommandType.DirectoryCreate,
      category: 'file',
      dataModel: 'DataDirectoryCreate',
      samplePath: 'assets/yaml/sample/07_file_utils.yaml',
    ),
  );
}
