ChatInputOmission constructor

ChatInputOmission({
  1. required ChatInputOmissionReason reason,
  2. required String resource,
  3. required bool truncated,
  4. int? limit,
  5. int? observedAtLeast,
})

Implementation

factory ChatInputOmission({
  required ChatInputOmissionReason reason,
  required String resource,
  required bool truncated,
  int? limit,
  int? observedAtLeast,
}) {
  final hasLimit = limit != null;
  final hasObservedAtLeast = observedAtLeast != null;
  if (hasLimit != hasObservedAtLeast) {
    throw ArgumentError(
      'limit and observedAtLeast must either both be provided or both be null',
    );
  }
  final hasCapacity = hasLimit;
  if (reason == ChatInputOmissionReason.inputLimit && !hasCapacity) {
    throw ArgumentError(
      'inputLimit omissions require limit and observedAtLeast',
    );
  }
  if (reason != ChatInputOmissionReason.inputLimit && hasCapacity) {
    throw ArgumentError(
      'only inputLimit omissions may include limit and observedAtLeast',
    );
  }
  return ChatInputOmission._(
    reason: reason,
    resource: resource,
    truncated: truncated,
    limit: limit,
    observedAtLeast: observedAtLeast,
  );
}