main function

void main()

Demo function to test the examples

Implementation

void main() {
  print('🚀 ACK Additional Properties Examples\n');

  // Example 1: User with preferences
  final userData = {
    'id': 'user_123',
    'name': 'John Doe',
    'email': 'john@example.com',
    // Additional properties stored in 'preferences'
    'theme': 'dark',
    'language': 'en',
    'notifications': true,
  };

  try {
    final user = userSchema.parse(userData) as Map<String, dynamic>;
    final prefs = user['preferences'] as Map<String, dynamic>;
    print('✅ User: ${user['name']} (${user['email']})');
    print('   Theme: ${prefs['theme']}');
    print('   Language: ${prefs['language']}');
    print('   Notifications: ${prefs['notifications']}\n');
  } catch (e) {
    print('❌ User error: $e\n');
  }

  // Example 2: Product with metadata
  final productData = {
    'id': 'prod_456',
    'name': 'Wireless Headphones',
    'price': 199.99,
    // Additional properties stored in 'metadata'
    'brand': 'TechCorp',
    'color': 'Black',
    'warranty': '2 years',
    'rating': 4.8,
  };

  try {
    final product = productSchema.parse(productData) as Map<String, dynamic>;
    final metadata = product['metadata'] as Map<String, dynamic>;
    print('✅ Product: ${product['name']} (\$${product['price']})');
    print('   Brand: ${metadata['brand']}');
    print('   Color: ${metadata['color']}');
    print('   Rating: ${metadata['rating']}\n');
  } catch (e) {
    print('❌ Product error: $e\n');
  }

  // Example 3: Simple model (extra fields ignored)
  final simpleData = {
    'id': 'item_789',
    'name': 'Basic Widget',
    'active': true,
    // These extra fields will be ignored
    'extra_field': 'ignored',
    'custom_data': {'some': 'data'},
  };

  try {
    final item = simpleItemSchema.parse(simpleData) as Map<String, dynamic>;
    print('✅ Simple Item: ${item['name']} (active: ${item['active']})');
    print('   Note: Extra fields are ignored in simple models\n');
  } catch (e) {
    print('❌ Simple item error: $e\n');
  }

  print('🎉 All examples completed!');
  print('💡 Key takeaway: Additional properties provide flexibility');
  print('   while maintaining type safety for core fields.');
}