declineCounter method

VCalendar declineCounter({
  1. AttendeeProperty? attendee,
  2. String? attendeeEmail,
  3. String? comment,
})

Declines a counter proposal.

An organizer can decline the counter proposal and optionally provide the reasoning in the comment.

When either the attendee or attendeeEmail is specified, only that attendee will be kept.

This calendar's method must be Method.counter.

The VEvent.sequence stays the same.

Compare counter for attendees to create a counter proposal.

Implementation

VCalendar declineCounter({
  AttendeeProperty? attendee,
  String? attendeeEmail,
  String? comment,
}) {
  assert(
    method == Method.counter,
    'The current method is not Method.counter but instead $method. '
    'Only counter proposals can be declined.',
  );

  final copied = copy() as VCalendar..method = Method.declineCounter;
  final event =
      copied.children.firstWhereOrNull((ev) => ev is VEvent) as VEvent?;
  if (event != null) {
    if (comment != null) {
      event.comment = comment;
    }
    if (attendee != null) {
      attendeeEmail = attendee.email;
    }
    if (attendeeEmail != null) {
      event.properties.removeWhere(
        (p) => p is AttendeeProperty && p.email != attendeeEmail,
      );
    }
  }

  return copied;
}