import 'package:hive_flutter/hive_flutter.dart';
import 'package:wallpaperx/entity/generate_info_model.dart';
import 'package:wallpaperx/entity/image_model.dart';
import 'package:wallpaperx/entity/tags_model.dart';

const favoriteBox = 'favoriteBox';
const historyBox = 'historyBox';
const customBox = 'customBox';

Future initHive() async {
  // 初始化
  await Hive.initFlutter();
  // 注册类型适配器
  Hive.registerAdapter(ImageModelAdapter());
  Hive.registerAdapter(GenerateInfoModelAdapter());
  Hive.registerAdapter(TagsModelAdapter());
  // 打开盒子
  await Hive.openBox<ImageModel>(favoriteBox);
  await Hive.openBox<ImageModel>(historyBox);
  await Hive.openBox<ImageModel>(customBox);
}

/// 获取盒子
Box<ImageModel> getFavoriteBox() {
  return Hive.box<ImageModel>(favoriteBox);
}

/// 获取盒子
Box<ImageModel> getHistoryBox() {
  return Hive.box<ImageModel>(historyBox);
}

/// 获取盒子
Box<ImageModel> getCustomBox() {
  return Hive.box<ImageModel>(customBox);
}