mirrored_repositories/flutter-objectbox-example
// GENERATED CODE - DO NOT MODIFY BY HAND
// This code was generated by ObjectBox. To update it run the generator again:
// With a Flutter package, run `flutter pub run build_runner build`.
// With a Dart package, run `dart run build_runner build`.
// See also https://docs.objectbox.io/getting-started#generate-objectbox-code

// ignore_for_file: camel_case_types

import 'dart:typed_data';

import 'package:flat_buffers/flat_buffers.dart' as fb;
import 'package:objectbox/internal.dart'; // generated code can access "internal" functionality
import 'package:objectbox/objectbox.dart';

import 'entities/expense.dart';
import 'entities/expense_type.dart';

export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file

final _entities = <ModelEntity>[
  ModelEntity(
      id: const IdUid(1, 7217190552277395867),
      name: 'Expense',
      lastPropertyId: const IdUid(5, 2663765814440690905),
      flags: 0,
      properties: <ModelProperty>[
        ModelProperty(
            id: const IdUid(1, 1527225490299843563),
            name: 'id',
            type: 6,
            flags: 1),
        ModelProperty(
            id: const IdUid(2, 259747063648648230),
            name: 'amount',
            type: 8,
            flags: 0),
        ModelProperty(
            id: const IdUid(3, 6298206329088241903),
            name: 'note',
            type: 9,
            flags: 0),
        ModelProperty(
            id: const IdUid(4, 6041035703793031442),
            name: 'date',
            type: 12,
            flags: 0),
        ModelProperty(
            id: const IdUid(5, 2663765814440690905),
            name: 'expenseTypeId',
            type: 11,
            flags: 520,
            indexId: const IdUid(1, 1723235740853294332),
            relationTarget: 'ExpenseType')
      ],
      relations: <ModelRelation>[],
      backlinks: <ModelBacklink>[]),
  ModelEntity(
      id: const IdUid(3, 687153607940665596),
      name: 'ExpenseType',
      lastPropertyId: const IdUid(3, 7116122762776967856),
      flags: 0,
      properties: <ModelProperty>[
        ModelProperty(
            id: const IdUid(1, 3927516500936406884),
            name: 'id',
            type: 6,
            flags: 1),
        ModelProperty(
            id: const IdUid(2, 6521466187271375061),
            name: 'identifier',
            type: 9,
            flags: 0),
        ModelProperty(
            id: const IdUid(3, 7116122762776967856),
            name: 'name',
            type: 9,
            flags: 2080,
            indexId: const IdUid(2, 4340554622386498839))
      ],
      relations: <ModelRelation>[],
      backlinks: <ModelBacklink>[
        ModelBacklink(name: 'expenses', srcEntity: 'Expense', srcField: '')
      ])
];

/// Open an ObjectBox store with the model declared in this file.
Store openStore(
        {String? directory,
        int? maxDBSizeInKB,
        int? fileMode,
        int? maxReaders,
        bool queriesCaseSensitiveDefault = true,
        String? macosApplicationGroup}) =>
    Store(getObjectBoxModel(),
        directory: directory,
        maxDBSizeInKB: maxDBSizeInKB,
        fileMode: fileMode,
        maxReaders: maxReaders,
        queriesCaseSensitiveDefault: queriesCaseSensitiveDefault,
        macosApplicationGroup: macosApplicationGroup);

/// ObjectBox model definition, pass it to [Store] - Store(getObjectBoxModel())
ModelDefinition getObjectBoxModel() {
  final model = ModelInfo(
      entities: _entities,
      lastEntityId: const IdUid(3, 687153607940665596),
      lastIndexId: const IdUid(2, 4340554622386498839),
      lastRelationId: const IdUid(0, 0),
      lastSequenceId: const IdUid(0, 0),
      retiredEntityUids: const [7620952543243995255],
      retiredIndexUids: const [],
      retiredPropertyUids: const [
        3845386833114662251,
        4882907920823481202,
        1850253826698914775
      ],
      retiredRelationUids: const [],
      modelVersion: 5,
      modelVersionParserMinimum: 5,
      version: 1);

  final bindings = <Type, EntityDefinition>{
    Expense: EntityDefinition<Expense>(
        model: _entities[0],
        toOneRelations: (Expense object) => [object.expenseType],
        toManyRelations: (Expense object) => {},
        getId: (Expense object) => object.id,
        setId: (Expense object, int id) {
          object.id = id;
        },
        objectToFB: (Expense object, fb.Builder fbb) {
          final noteOffset = fbb.writeString(object.note);
          fbb.startTable(6);
          fbb.addInt64(0, object.id);
          fbb.addFloat64(1, object.amount);
          fbb.addOffset(2, noteOffset);
          fbb.addInt64(3, object.date.microsecondsSinceEpoch * 1000);
          fbb.addInt64(4, object.expenseType.targetId);
          fbb.finish(fbb.endTable());
          return object.id;
        },
        objectFromFB: (Store store, ByteData fbData) {
          final buffer = fb.BufferContext(fbData);
          final rootOffset = buffer.derefObject(0);

          final object = Expense(
              id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0),
              amount:
                  const fb.Float64Reader().vTableGet(buffer, rootOffset, 6, 0),
              note: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 8, ''),
              date: DateTime.fromMicrosecondsSinceEpoch(
                  (const fb.Int64Reader().vTableGet(buffer, rootOffset, 10, 0) /
                          1000)
                      .round()));
          object.expenseType.targetId =
              const fb.Int64Reader().vTableGet(buffer, rootOffset, 12, 0);
          object.expenseType.attach(store);
          return object;
        }),
    ExpenseType: EntityDefinition<ExpenseType>(
        model: _entities[1],
        toOneRelations: (ExpenseType object) => [],
        toManyRelations: (ExpenseType object) => {
              RelInfo<Expense>.toOneBacklink(5, object.id,
                  (Expense srcObject) => srcObject.expenseType): object.expenses
            },
        getId: (ExpenseType object) => object.id,
        setId: (ExpenseType object, int id) {
          object.id = id;
        },
        objectToFB: (ExpenseType object, fb.Builder fbb) {
          final identifierOffset = fbb.writeString(object.identifier);
          final nameOffset = fbb.writeString(object.name);
          fbb.startTable(4);
          fbb.addInt64(0, object.id);
          fbb.addOffset(1, identifierOffset);
          fbb.addOffset(2, nameOffset);
          fbb.finish(fbb.endTable());
          return object.id;
        },
        objectFromFB: (Store store, ByteData fbData) {
          final buffer = fb.BufferContext(fbData);
          final rootOffset = buffer.derefObject(0);

          final object = ExpenseType(
              id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0),
              identifier: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 6, ''),
              name: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 8, ''));
          InternalToManyAccess.setRelInfo(
              object.expenses,
              store,
              RelInfo<Expense>.toOneBacklink(
                  5, object.id, (Expense srcObject) => srcObject.expenseType),
              store.box<ExpenseType>());
          return object;
        })
  };

  return ModelDefinition(model, bindings);
}

/// [Expense] entity fields to define ObjectBox queries.
class Expense_ {
  /// see [Expense.id]
  static final id = QueryIntegerProperty<Expense>(_entities[0].properties[0]);

  /// see [Expense.amount]
  static final amount =
      QueryDoubleProperty<Expense>(_entities[0].properties[1]);

  /// see [Expense.note]
  static final note = QueryStringProperty<Expense>(_entities[0].properties[2]);

  /// see [Expense.date]
  static final date = QueryIntegerProperty<Expense>(_entities[0].properties[3]);

  /// see [Expense.expenseType]
  static final expenseType =
      QueryRelationToOne<Expense, ExpenseType>(_entities[0].properties[4]);
}

/// [ExpenseType] entity fields to define ObjectBox queries.
class ExpenseType_ {
  /// see [ExpenseType.id]
  static final id =
      QueryIntegerProperty<ExpenseType>(_entities[1].properties[0]);

  /// see [ExpenseType.identifier]
  static final identifier =
      QueryStringProperty<ExpenseType>(_entities[1].properties[1]);

  /// see [ExpenseType.name]
  static final name =
      QueryStringProperty<ExpenseType>(_entities[1].properties[2]);
}
