import 'package:diameter/main.dart';
import 'package:diameter/models/basal_profile.dart';
import 'package:diameter/models/bolus_profile.dart';
import 'package:objectbox/objectbox.dart';
import 'package:diameter/objectbox.g.dart' show LogEventType_;

@Entity(uid: 8362795406595606110)
@Sync()
class LogEventType {
  static final Box<LogEventType> box = objectBox.store.box<LogEventType>();

  // properties
  int id;
  bool deleted;
  String value;
  bool hasEndTime;
  int? defaultReminderDuration;
  String? notes;

  // constructor
  LogEventType({
    this.id = 0,
    this.deleted = false,
    this.value = '',
    this.hasEndTime = false,
    this.defaultReminderDuration,
    this.notes,
  });

  // relations
  final bolusProfile = ToOne<BolusProfile>();
  final basalProfile = ToOne<BasalProfile>();

  // methods
  static LogEventType? get(int id) => box.get(id);
  static void put(LogEventType logEventType) => box.put(logEventType);
  
  static List<LogEventType> getAll() {
    QueryBuilder<LogEventType> builder = box.query(LogEventType_.deleted.equals(false))..order(LogEventType_.value);
    return builder.build().find();
  }
  
  static void remove(int id) {
    final item = box.get(id);
    if (item != null) {
      item.deleted = true;
      box.put(item);
    }
  }

  @override
  String toString() {
    return value;
  }
}
