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

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

  @override
  Future execute(DataCommand command) async {
    var data = DataSMBAuthorize.fromJson(getParam(command));
    final result = await runtime.runExecutable('cmd', [
      '/C',
      'net',
      'use',
      '\\\\${data.domain}',
      '/user:${data.id}',
      data.password
    ]);
    return complete(result.exitCode, command);
  }
}

void registerInfraCommands() {
  Command.register(
    CommandType.SMBAuth,
    () => SMBAuth(),
    spec: const CommandSpec(
      type: CommandType.SMBAuth,
      category: 'infra',
      dataModel: 'DataSMBAuthorize',
    ),
  );
}
