import 'package:hive/hive.dart';

part 'display_data.g.dart';

@HiveType(typeId: 11)
class DisplayData extends HiveObject {
  @HiveField(0)
  final String name;

  @HiveField(1)
  final String brewery;

  @HiveField(2)
  final String prefecture;

  @HiveField(3)
  final String? catchCopy;

  @HiveField(4)
  final List<String> imagePaths;

  @HiveField(5)
  final double? rating;

  // ✅ さけのわデータ（統一名称用）- 表示時にこちらを優先
  @HiveField(6)
  final String? sakenowaName;

  @HiveField(7)
  final String? sakenowaBrewery;

  @HiveField(8)
  final String? sakenowaPrefecture;

  DisplayData({
    required this.name,
    required this.brewery,
    required this.prefecture,
    this.catchCopy,
    required this.imagePaths,
    this.rating,
    // さけのわデータ（オプショナル）
    this.sakenowaName,
    this.sakenowaBrewery,
    this.sakenowaPrefecture,
  });

  // ✅ 表示用ゲッター：さけのわデータ優先、なければGeminiデータ
  String get displayName => sakenowaName ?? name;
  String get displayBrewery => sakenowaBrewery ?? brewery;
  String get displayPrefecture => sakenowaPrefecture ?? prefecture;

  // ✅ さけのわデータが設定されているか
  bool get hasSakenowaData => sakenowaName != null;

  DisplayData copyWith({
    String? name,
    String? brewery,
    String? prefecture,
    String? catchCopy,
    List<String>? imagePaths,
    double? rating,
    String? sakenowaName,
    String? sakenowaBrewery,
    String? sakenowaPrefecture,
  }) {
    return DisplayData(
      name: name ?? this.name,
      brewery: brewery ?? this.brewery,
      prefecture: prefecture ?? this.prefecture,
      catchCopy: catchCopy ?? this.catchCopy,
      imagePaths: imagePaths ?? this.imagePaths,
      rating: rating ?? this.rating,
      sakenowaName: sakenowaName ?? this.sakenowaName,
      sakenowaBrewery: sakenowaBrewery ?? this.sakenowaBrewery,
      sakenowaPrefecture: sakenowaPrefecture ?? this.sakenowaPrefecture,
    );
  }
}
