main function

Future<void> main()

Implementation

Future<void> main() async {
  await RustLib.init();

  // Load environment variables
  final env = DotEnv(includePlatformEnvironment: true);
  try {
    env.load(['.env']);
  } catch (e) {
    // .env file doesn't exist or couldn't be loaded
    print('Note: .env file not found, will prompt for credentials');
  }

  print('=== VTOP Terminal Client ===');
  print('Welcome to VIT VTOP Command Line Interface\n');

  // Get login credentials from environment or user input
  String username = env['VTOP_USERNAME'] ?? '';
  String password = env['VTOP_PASSWORD'] ?? '';

  if (username.isEmpty || password.isEmpty) {
    print('Credentials not found in .env file, please enter manually:');

    if (username.isEmpty) {
      stdout.write('Enter Username: ');
      username = stdin.readLineSync() ?? '';
    } else {
      print('Using username from .env: $username');
    }

    if (password.isEmpty) {
      stdout.write('Enter Password: ');
      stdin.echoMode = false; // Hide password input
      password = stdin.readLineSync() ?? '';
      stdin.echoMode = true;
      print('');
    } else {
      print('Using password from .env file');
    }
  } else {
    print('Using credentials from .env file');
    print('Username: $username');
  }

  if (username.isEmpty || password.isEmpty) {
    print('Error: Username and password cannot be empty');
    exit(1);
  }

  try {
    // Create VTOP client
    print('Creating VTOP client...');
    final client = getVtopClient(username: username, password: password);
    print('✓ Client created successfully');

    // Login
    print('Logging in...');
    await vtopClientLogin(client: client);
    print('✓ Login successful\n');

    // Main menu loop
    while (true) {
      print('=== VTOP Actions ===');
      print('1. Fetch Semesters');
      print('2. Fetch Attendance');
      print('3. Fetch Timetable');
      print('4. Fetch Marks');
      print('5. Fetch Exam Schedule');
      print('6. Fetch Student Profile');
      print('7. Fetch Grade History');
      print('8. Fetch Payment Receipts');
      print('9. Fetch Pending Payments');
      print('10. Fetch Biometric Data');
      print('11. Faculty Search');
      print('12. Hostel Reports');
      print('13. WiFi Login/Logout');
      print('14. Test Rust Bridge');
      print('0. Exit');
      stdout.write('\nSelect an option (0-14): ');

      final choice = stdin.readLineSync() ?? '';
      print('');

      switch (choice) {
        case '1':
          await fetchAndDisplaySemesters(client);
          break;
        case '2':
          await fetchAndDisplayAttendance(client);
          break;
        case '3':
          await fetchAndDisplayTimetable(client);
          break;
        case '4':
          await fetchAndDisplayMarks(client);
          break;
        case '5':
          await fetchAndDisplayExamSchedule(client);
          break;
        case '6':
          await fetchAndDisplayStudentProfile(client);
          break;
        case '7':
          await fetchAndDisplayGradeHistory(client);
          break;
        case '8':
          await fetchAndDisplayPaymentReceipts(client);
          break;
        case '9':
          await fetchAndDisplayPendingPayments(client);
          break;
        case '10':
          await fetchAndDisplayBiometricData(client);
          break;
        case '11':
          await facultySearchAndDisplay(client);
          break;
        case '12':
          await hostelReportsMenu(client);
          break;
        case '13':
          await wifiLoginLogout();
          break;
        case '14':
          testRustBridge();
          break;
        case '0':
          print('Goodbye!');
          exit(0);
        default:
          print('Invalid option. Please try again.\n');
      }
    }
  } catch (e) {
    print('Error: $e');
    exit(1);
  }
}