toJson method

  1. @override
Map<String, dynamic> toJson()
override

Implementation

@override
Map<String, dynamic> toJson() {
  return {
    'type': _type.value,
    'custom_id': _customId,
    'placeholder': _placeholder,
    'disabled': _disabled,
    if (_minValues != null) 'min_values': _minValues,
    if (_maxValues != null) 'max_values': _maxValues,
    if (_minLength != null) 'min_length': _minLength,
    if (_maxLength != null) 'max_length': _maxLength,
    if (_options.isNotEmpty)
      'options': _options.map((e) => e.toJson()).toList(),
    if (_channelTypes.isNotEmpty)
      'channel_types': _channelTypes.map((e) => e.value).toList(),
    if (_defaultValues.isNotEmpty)
      'default_values': _defaultValues
          .map((e) => {
                'id': e.value,
                'type': switch (_type) {
                  ComponentType.userSelectMenu => 'user',
                  ComponentType.roleSelectMenu => 'role',
                  ComponentType.channelSelectMenu => 'channel',
                  _ => throw Exception('Invalid select menu type'),
                },
              })
          .toList(),
  };
}