import 'package:hive/hive.dart';

part 'sake_taste_stats.g.dart';

@HiveType(typeId: 21)
class SakeTasteStats extends HiveObject {
  @HiveField(0)
  final double aroma; // 香り

  @HiveField(1)
  final double bitterness; // キレ (苦味) - Old: richness

  @HiveField(2)
  final double sweetness; // 甘み

  @HiveField(3)
  final double acidity; // 酸味 - Old: alcoholFeeling

  @HiveField(4)
  final double body; // コク - Old: fruitiness

  SakeTasteStats({
    required this.aroma,
    required this.bitterness,
    required this.sweetness,
    required this.acidity,
    required this.body,
  });
  
  // Factory to convert from Map (Handles Schema Migration)
  factory SakeTasteStats.fromMap(Map<String, int> map) {
    return SakeTasteStats(
      aroma: (map['aroma'] ?? 0).toDouble(),
      sweetness: (map['sweetness'] ?? 0).toDouble(),
      
      // Fallback Logic: New Key -> Old Key -> Default
      // Gemini now returns 'acidity', 'bitterness', 'body'
      acidity: (map['acidity'] ?? map['alcohol'] ?? map['alcoholFeeling'] ?? 0).toDouble(),
      bitterness: (map['bitterness'] ?? map['richness'] ?? 0).toDouble(),
      body: (map['body'] ?? map['fruitiness'] ?? 0).toDouble(),
    );
  }
}
