DocumentReference<T extends Object?> constructor

DocumentReference<T extends Object?>(
  1. {required QueryHelper helper,
  2. required FusabaseOracledb oracledb,
  3. required String path,
  4. dynamic parent_}
)

Implementation

DocumentReference({
  required QueryHelper helper,
  required FusabaseOracledb oracledb,
  required String path,
  dynamic parent_,
}) : _id = "",
     _helper = helper,
     _rt = 0,
     __logLevel = oracledb.app.logLevel,
     type = "document",
     _vectorSearch = null,
     _oracledb = oracledb {
  path = path.toString().trim();
  List<String> tokens = path.split('/');

  this._id = tokens.removeAt(tokens.length - 1);

  if (_id == "") {
    throw Utils.oracledbErrorHandler(
      400,
      OracledbErrorMessages.incorrectDocumentId,
      null,
    );
  }
  _path = [];
  if (parent_ != null) {
    _parent = parent_;
  } else {
    if (tokens.isEmpty) {
      _parent = null;
    } else {
      _parent = oracledb.collection(tokens.join('/'));
    }
  }

  _path = (_parent != null) ? [...(_parent?._path ?? [])] : [];
  _path.add(_id);

  if (_path.length % 2 != 0) {
    throw Utils.oracledbErrorHandler(400, "Incorrect document path.", null);
  }

  if (_parent == null) {
    throw Utils.oracledbErrorHandler(
      400,
      OracledbErrorMessages.parentCollectionCannotBeNull,
      null,
    );
  }

  if (_parent is DocumentReference) {
    throw Utils.oracledbErrorHandler(400, "Parent can't be a document", null);
  }
}