import 'package:diameter/main.dart';
import 'package:objectbox/objectbox.dart';
import 'package:diameter/objectbox.g.dart' show MealPortionType_;

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

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

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

  // methods
  static MealPortionType? get(int id) => box.get(id);
  static void put(MealPortionType mealPortionType) => box.put(mealPortionType);
  
  static List<MealPortionType> getAll() {
    QueryBuilder<MealPortionType> builder = box.query(MealPortionType_.deleted.equals(false))..order(MealPortionType_.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;
  }
}
