/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
/*   To generate run: "serverpod generate"    */

// ignore_for_file: implementation_imports
// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: public_member_api_docs
// ignore_for_file: type_literal_in_constant_pattern
// ignore_for_file: use_super_parameters

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:serverpod/serverpod.dart' as _i1;

abstract class Health implements _i1.TableRow<int?>, _i1.ProtocolSerialization {
  Health._({
    this.id,
    required this.createdAt,
    this.note,
  });

  factory Health({
    int? id,
    required DateTime createdAt,
    String? note,
  }) = _HealthImpl;

  factory Health.fromJson(Map<String, dynamic> jsonSerialization) {
    return Health(
      id: jsonSerialization['id'] as int?,
      createdAt:
          _i1.DateTimeJsonExtension.fromJson(jsonSerialization['createdAt']),
      note: jsonSerialization['note'] as String?,
    );
  }

  static final t = HealthTable();

  static const db = HealthRepository._();

  @override
  int? id;

  DateTime createdAt;

  String? note;

  @override
  _i1.Table<int?> get table => t;

  /// Returns a shallow copy of this [Health]
  /// with some or all fields replaced by the given arguments.
  @_i1.useResult
  Health copyWith({
    int? id,
    DateTime? createdAt,
    String? note,
  });
  @override
  Map<String, dynamic> toJson() {
    return {
      if (id != null) 'id': id,
      'createdAt': createdAt.toJson(),
      if (note != null) 'note': note,
    };
  }

  @override
  Map<String, dynamic> toJsonForProtocol() {
    return {
      if (id != null) 'id': id,
      'createdAt': createdAt.toJson(),
      if (note != null) 'note': note,
    };
  }

  static HealthInclude include() {
    return HealthInclude._();
  }

  static HealthIncludeList includeList({
    _i1.WhereExpressionBuilder<HealthTable>? where,
    int? limit,
    int? offset,
    _i1.OrderByBuilder<HealthTable>? orderBy,
    bool orderDescending = false,
    _i1.OrderByListBuilder<HealthTable>? orderByList,
    HealthInclude? include,
  }) {
    return HealthIncludeList._(
      where: where,
      limit: limit,
      offset: offset,
      orderBy: orderBy?.call(Health.t),
      orderDescending: orderDescending,
      orderByList: orderByList?.call(Health.t),
      include: include,
    );
  }

  @override
  String toString() {
    return _i1.SerializationManager.encode(this);
  }
}

class _Undefined {}

class _HealthImpl extends Health {
  _HealthImpl({
    int? id,
    required DateTime createdAt,
    String? note,
  }) : super._(
          id: id,
          createdAt: createdAt,
          note: note,
        );

  /// Returns a shallow copy of this [Health]
  /// with some or all fields replaced by the given arguments.
  @_i1.useResult
  @override
  Health copyWith({
    Object? id = _Undefined,
    DateTime? createdAt,
    Object? note = _Undefined,
  }) {
    return Health(
      id: id is int? ? id : this.id,
      createdAt: createdAt ?? this.createdAt,
      note: note is String? ? note : this.note,
    );
  }
}

class HealthTable extends _i1.Table<int?> {
  HealthTable({super.tableRelation}) : super(tableName: 'health') {
    createdAt = _i1.ColumnDateTime(
      'createdAt',
      this,
    );
    note = _i1.ColumnString(
      'note',
      this,
    );
  }

  late final _i1.ColumnDateTime createdAt;

  late final _i1.ColumnString note;

  @override
  List<_i1.Column> get columns => [
        id,
        createdAt,
        note,
      ];
}

class HealthInclude extends _i1.IncludeObject {
  HealthInclude._();

  @override
  Map<String, _i1.Include?> get includes => {};

  @override
  _i1.Table<int?> get table => Health.t;
}

class HealthIncludeList extends _i1.IncludeList {
  HealthIncludeList._({
    _i1.WhereExpressionBuilder<HealthTable>? where,
    super.limit,
    super.offset,
    super.orderBy,
    super.orderDescending,
    super.orderByList,
    super.include,
  }) {
    super.where = where?.call(Health.t);
  }

  @override
  Map<String, _i1.Include?> get includes => include?.includes ?? {};

  @override
  _i1.Table<int?> get table => Health.t;
}

class HealthRepository {
  const HealthRepository._();

  /// Returns a list of [Health]s matching the given query parameters.
  ///
  /// Use [where] to specify which items to include in the return value.
  /// If none is specified, all items will be returned.
  ///
  /// To specify the order of the items use [orderBy] or [orderByList]
  /// when sorting by multiple columns.
  ///
  /// The maximum number of items can be set by [limit]. If no limit is set,
  /// all items matching the query will be returned.
  ///
  /// [offset] defines how many items to skip, after which [limit] (or all)
  /// items are read from the database.
  ///
  /// ```dart
  /// var persons = await Persons.db.find(
  ///   session,
  ///   where: (t) => t.lastName.equals('Jones'),
  ///   orderBy: (t) => t.firstName,
  ///   limit: 100,
  /// );
  /// ```
  Future<List<Health>> find(
    _i1.Session session, {
    _i1.WhereExpressionBuilder<HealthTable>? where,
    int? limit,
    int? offset,
    _i1.OrderByBuilder<HealthTable>? orderBy,
    bool orderDescending = false,
    _i1.OrderByListBuilder<HealthTable>? orderByList,
    _i1.Transaction? transaction,
  }) async {
    return session.db.find<Health>(
      where: where?.call(Health.t),
      orderBy: orderBy?.call(Health.t),
      orderByList: orderByList?.call(Health.t),
      orderDescending: orderDescending,
      limit: limit,
      offset: offset,
      transaction: transaction,
    );
  }

  /// Returns the first matching [Health] matching the given query parameters.
  ///
  /// Use [where] to specify which items to include in the return value.
  /// If none is specified, all items will be returned.
  ///
  /// To specify the order use [orderBy] or [orderByList]
  /// when sorting by multiple columns.
  ///
  /// [offset] defines how many items to skip, after which the next one will be picked.
  ///
  /// ```dart
  /// var youngestPerson = await Persons.db.findFirstRow(
  ///   session,
  ///   where: (t) => t.lastName.equals('Jones'),
  ///   orderBy: (t) => t.age,
  /// );
  /// ```
  Future<Health?> findFirstRow(
    _i1.Session session, {
    _i1.WhereExpressionBuilder<HealthTable>? where,
    int? offset,
    _i1.OrderByBuilder<HealthTable>? orderBy,
    bool orderDescending = false,
    _i1.OrderByListBuilder<HealthTable>? orderByList,
    _i1.Transaction? transaction,
  }) async {
    return session.db.findFirstRow<Health>(
      where: where?.call(Health.t),
      orderBy: orderBy?.call(Health.t),
      orderByList: orderByList?.call(Health.t),
      orderDescending: orderDescending,
      offset: offset,
      transaction: transaction,
    );
  }

  /// Finds a single [Health] by its [id] or null if no such row exists.
  Future<Health?> findById(
    _i1.Session session,
    int id, {
    _i1.Transaction? transaction,
  }) async {
    return session.db.findById<Health>(
      id,
      transaction: transaction,
    );
  }

  /// Inserts all [Health]s in the list and returns the inserted rows.
  ///
  /// The returned [Health]s will have their `id` fields set.
  ///
  /// This is an atomic operation, meaning that if one of the rows fails to
  /// insert, none of the rows will be inserted.
  Future<List<Health>> insert(
    _i1.Session session,
    List<Health> rows, {
    _i1.Transaction? transaction,
  }) async {
    return session.db.insert<Health>(
      rows,
      transaction: transaction,
    );
  }

  /// Inserts a single [Health] and returns the inserted row.
  ///
  /// The returned [Health] will have its `id` field set.
  Future<Health> insertRow(
    _i1.Session session,
    Health row, {
    _i1.Transaction? transaction,
  }) async {
    return session.db.insertRow<Health>(
      row,
      transaction: transaction,
    );
  }

  /// Updates all [Health]s in the list and returns the updated rows. If
  /// [columns] is provided, only those columns will be updated. Defaults to
  /// all columns.
  /// This is an atomic operation, meaning that if one of the rows fails to
  /// update, none of the rows will be updated.
  Future<List<Health>> update(
    _i1.Session session,
    List<Health> rows, {
    _i1.ColumnSelections<HealthTable>? columns,
    _i1.Transaction? transaction,
  }) async {
    return session.db.update<Health>(
      rows,
      columns: columns?.call(Health.t),
      transaction: transaction,
    );
  }

  /// Updates a single [Health]. The row needs to have its id set.
  /// Optionally, a list of [columns] can be provided to only update those
  /// columns. Defaults to all columns.
  Future<Health> updateRow(
    _i1.Session session,
    Health row, {
    _i1.ColumnSelections<HealthTable>? columns,
    _i1.Transaction? transaction,
  }) async {
    return session.db.updateRow<Health>(
      row,
      columns: columns?.call(Health.t),
      transaction: transaction,
    );
  }

  /// Deletes all [Health]s in the list and returns the deleted rows.
  /// This is an atomic operation, meaning that if one of the rows fail to
  /// be deleted, none of the rows will be deleted.
  Future<List<Health>> delete(
    _i1.Session session,
    List<Health> rows, {
    _i1.Transaction? transaction,
  }) async {
    return session.db.delete<Health>(
      rows,
      transaction: transaction,
    );
  }

  /// Deletes a single [Health].
  Future<Health> deleteRow(
    _i1.Session session,
    Health row, {
    _i1.Transaction? transaction,
  }) async {
    return session.db.deleteRow<Health>(
      row,
      transaction: transaction,
    );
  }

  /// Deletes all rows matching the [where] expression.
  Future<List<Health>> deleteWhere(
    _i1.Session session, {
    required _i1.WhereExpressionBuilder<HealthTable> where,
    _i1.Transaction? transaction,
  }) async {
    return session.db.deleteWhere<Health>(
      where: where(Health.t),
      transaction: transaction,
    );
  }

  /// Counts the number of rows matching the [where] expression. If omitted,
  /// will return the count of all rows in the table.
  Future<int> count(
    _i1.Session session, {
    _i1.WhereExpressionBuilder<HealthTable>? where,
    int? limit,
    _i1.Transaction? transaction,
  }) async {
    return session.db.count<Health>(
      where: where?.call(Health.t),
      limit: limit,
      transaction: transaction,
    );
  }
}
