djs-model 0.1.0-alpha.1

Discord API v10 types — users, guilds, channels, messages, interactions and gateway events.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
//! Interactive components: buttons, select menus and modal inputs.

use compact_str::CompactString;
use serde::{Serialize, Serializer};

use crate::{
    channel::ChannelType,
    emoji::PartialEmoji,
    id::{GenericId, SkuId},
    macros::{int_enum, str_enum},
};

/// A [button](https://docs.discord.com/developers/components/reference#button), in an
/// [action row](super::ActionRow) or as a [section](super::Section) accessory (messages only).
///
/// Its `style` decides which fields it has (D-066). Link and premium buttons do not send an
/// interaction when clicked.
///
/// discord.js counterpart: `ButtonComponent` / `ButtonBuilder`.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
#[doc(alias = "ButtonComponent")]
pub enum Button {
    /// A button with a `custom_id` that sends an interaction (styles 1-4).
    Interactive(InteractiveButton),
    /// A button that opens a URL (style 5).
    Link(LinkButton),
    /// A button that opens the purchase of an SKU (style 6).
    Premium(PremiumButton),
    /// A button style this version of the library does not know about (boxed: it keeps every
    /// button field).
    Unknown(Box<UnknownButton>),
}

impl Button {
    /// Returns the component's numeric identifier, if set.
    ///
    /// discord.js counterpart: `ButtonComponent#id`.
    #[must_use]
    pub const fn id(&self) -> Option<i32> {
        match self {
            Self::Interactive(button) => button.id,
            Self::Link(button) => button.id,
            Self::Premium(button) => button.id,
            Self::Unknown(button) => button.id,
        }
    }

    /// Returns the button's style.
    ///
    /// discord.js counterpart: `ButtonComponent#style`.
    #[must_use]
    pub const fn style(&self) -> ButtonStyle {
        match self {
            Self::Interactive(button) => button.style,
            Self::Link(_) => ButtonStyle::Link,
            Self::Premium(_) => ButtonStyle::Premium,
            Self::Unknown(button) => button.style,
        }
    }

    /// Returns the developer-defined identifier of an interactive button.
    ///
    /// discord.js counterpart: `ButtonComponent#customId`.
    #[must_use]
    pub fn custom_id(&self) -> Option<&str> {
        match self {
            Self::Interactive(button) => Some(&button.custom_id),
            Self::Unknown(button) => button.custom_id.as_deref(),
            Self::Link(_) | Self::Premium(_) => None,
        }
    }

    /// Whether the button is disabled.
    ///
    /// discord.js counterpart: `ButtonComponent#disabled`.
    #[must_use]
    pub const fn disabled(&self) -> bool {
        match self {
            Self::Interactive(button) => button.disabled,
            Self::Link(button) => button.disabled,
            Self::Premium(button) => button.disabled,
            Self::Unknown(button) => button.disabled,
        }
    }
}

/// Serializes a button variant together with its `style`.
#[derive(Serialize)]
struct Styled<'a, T> {
    style: ButtonStyle,
    #[serde(flatten)]
    button: &'a T,
}

impl Serialize for Button {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let style = self.style();
        match self {
            Self::Interactive(button) => Styled { style, button }.serialize(serializer),
            Self::Link(button) => Styled { style, button }.serialize(serializer),
            Self::Premium(button) => Styled { style, button }.serialize(serializer),
            Self::Unknown(button) => Styled { style, button }.serialize(serializer),
        }
    }
}

/// A button that sends an interaction with its [`custom_id`](Self::custom_id) when clicked
/// (styles [`Primary`](ButtonStyle::Primary) to [`Danger`](ButtonStyle::Danger)).
///
/// discord.js counterpart: `APIButtonComponentWithCustomId` (discord-api-types).
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct InteractiveButton {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The style: one of `Primary`, `Secondary`, `Success`, `Danger`.
    #[serde(skip)]
    pub style: ButtonStyle,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The text on the button (max 80 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<CompactString>,
    /// The emoji on the button.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji: Option<PartialEmoji>,
    /// Whether the button is disabled.
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

impl InteractiveButton {
    /// Creates an enabled button without label or emoji (set at least one before sending).
    ///
    /// discord.js counterpart: `ButtonBuilder` (`@discordjs/builders`).
    #[must_use]
    pub fn new(style: ButtonStyle, custom_id: impl Into<CompactString>) -> Self {
        Self {
            id: None,
            style,
            custom_id: custom_id.into(),
            label: None,
            emoji: None,
            disabled: false,
        }
    }
}

/// A button that opens a [`url`](Self::url) (style [`Link`](ButtonStyle::Link)).
///
/// discord.js counterpart: `APIButtonComponentWithURL` (discord-api-types).
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct LinkButton {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The URL (max 512 characters).
    pub url: CompactString,
    /// The text on the button (max 80 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<CompactString>,
    /// The emoji on the button.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji: Option<PartialEmoji>,
    /// Whether the button is disabled.
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

impl LinkButton {
    /// Creates an enabled link button without label or emoji (set at least one before sending).
    ///
    /// discord.js counterpart: `ButtonBuilder` with `setURL` (`@discordjs/builders`).
    #[must_use]
    pub fn new(url: impl Into<CompactString>) -> Self {
        Self {
            id: None,
            url: url.into(),
            label: None,
            emoji: None,
            disabled: false,
        }
    }
}

/// A button that starts the purchase of an [SKU](crate::sku) (style
/// [`Premium`](ButtonStyle::Premium)). It shows the SKU's name and price; it cannot have a
/// label or emoji.
///
/// discord.js counterpart: `APIButtonComponentWithSKUId` (discord-api-types).
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct PremiumButton {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The SKU to purchase.
    pub sku_id: SkuId,
    /// Whether the button is disabled.
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

impl PremiumButton {
    /// Creates an enabled premium button.
    ///
    /// discord.js counterpart: `ButtonBuilder` with `setSKUId` (`@discordjs/builders`).
    #[must_use]
    pub const fn new(sku_id: SkuId) -> Self {
        Self {
            id: None,
            sku_id,
            disabled: false,
        }
    }
}

/// A button whose style this version of the library does not know about; every button field is
/// kept.
///
/// discord.js counterpart: none (a button style unknown to this version, kept as received).
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct UnknownButton {
    /// The component's numeric identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The raw style.
    #[serde(skip)]
    pub style: ButtonStyle,
    /// The developer-defined identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_id: Option<CompactString>,
    /// The text on the button.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<CompactString>,
    /// The emoji on the button.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji: Option<PartialEmoji>,
    /// The URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<CompactString>,
    /// The SKU.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sku_id: Option<SkuId>,
    /// Whether the button is disabled.
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

int_enum! {
    /// The [style of a button](https://docs.discord.com/developers/components/reference#button-button-styles).
    ///
    /// discord.js counterpart: `ButtonStyle`.
    pub enum ButtonStyle: u8 {
        /// The most important or recommended action (blurple).
        Primary = 1,
        /// An alternative or supporting action (grey).
        Secondary = 2,
        /// A positive confirmation or completion (green).
        Success = 3,
        /// An action with irreversible consequences (red).
        Danger = 4,
        /// Opens a URL.
        Link = 5,
        /// Starts a purchase.
        Premium = 6,
    }
}

/// A [string select](https://docs.discord.com/developers/components/reference#string-select):
/// a menu of developer-defined options (in an action row in messages, in a label in modals).
///
/// discord.js counterpart: `StringSelectMenuComponent` / `StringSelectMenuBuilder`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
#[doc(alias = "StringSelectMenu")]
pub struct StringSelect {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The options (max 25).
    pub options: Vec<SelectOption>,
    /// The text shown when nothing is selected (max 150 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<CompactString>,
    /// The minimum number of options to choose (Discord's default: 1; 0-25).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_values: Option<u8>,
    /// The maximum number of options to choose (Discord's default: 1; max 25).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_values: Option<u8>,
    /// Whether an answer is required in a modal (default `true`; ignored in messages).
    pub required: bool,
    /// Whether the menu is disabled (messages only; modals reject it).
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

impl StringSelect {
    /// Creates a select menu with the given options.
    ///
    /// discord.js counterpart: `StringSelectMenuBuilder` (`@discordjs/builders`).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>, options: Vec<SelectOption>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            options,
            placeholder: None,
            min_values: None,
            max_values: None,
            required: true,
            disabled: false,
        }
    }
}

/// An [option of a string select](https://docs.discord.com/developers/components/reference#string-select-select-option-structure).
///
/// discord.js counterpart: `APISelectMenuOption` / `StringSelectMenuOptionBuilder`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct SelectOption {
    /// The text shown to the user (max 100 characters).
    pub label: CompactString,
    /// The developer-defined value (max 100 characters).
    pub value: CompactString,
    /// An additional description (max 100 characters).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<CompactString>,
    /// The emoji.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub emoji: Option<PartialEmoji>,
    /// Whether the option is selected by default.
    #[serde(default, skip_serializing_if = "core::ops::Not::not")]
    pub default: bool,
}

impl SelectOption {
    /// Creates an option.
    ///
    /// discord.js counterpart: `StringSelectMenuOptionBuilder` (`@discordjs/builders`).
    #[must_use]
    pub fn new(label: impl Into<CompactString>, value: impl Into<CompactString>) -> Self {
        Self {
            label: label.into(),
            value: value.into(),
            description: None,
            emoji: None,
            default: false,
        }
    }
}

/// A [text input](https://docs.discord.com/developers/components/reference#text-input) in a
/// modal (inside a [label](super::Label)).
///
/// discord.js counterpart: `TextInputComponent` / `TextInputBuilder`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct TextInput {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// Single-line or multi-line.
    pub style: TextInputStyle,
    /// The label above the input. **Deprecated** by Discord: put the input in a
    /// [`Label`](super::Label) instead.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<CompactString>,
    /// The minimum length (0-4000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_length: Option<u16>,
    /// The maximum length (1-4000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_length: Option<u16>,
    /// Whether the input must be filled (default `true`).
    pub required: bool,
    /// The pre-filled value (max 4000 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<CompactString>,
    /// The text shown when the input is empty (max 100 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<CompactString>,
}

impl TextInput {
    /// Creates a required text input.
    ///
    /// discord.js counterpart: `TextInputBuilder` (`@discordjs/builders`).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>, style: TextInputStyle) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            style,
            label: None,
            min_length: None,
            max_length: None,
            required: true,
            value: None,
            placeholder: None,
        }
    }
}

int_enum! {
    /// The [style of a text input](https://docs.discord.com/developers/components/reference#text-input-text-input-styles).
    ///
    /// discord.js counterpart: `TextInputStyle`.
    pub enum TextInputStyle: u8 {
        /// A single line.
        Short = 1,
        /// Several lines.
        Paragraph = 2,
    }
}

/// A select menu whose options Discord fills in: the [user](https://docs.discord.com/developers/components/reference#user-select),
/// [role](https://docs.discord.com/developers/components/reference#role-select) and
/// [mentionable](https://docs.discord.com/developers/components/reference#mentionable-select)
/// selects share this structure (see [`ChannelSelect`] for channels).
///
/// discord.js counterpart: `UserSelectMenuComponent`, `RoleSelectMenuComponent`,
/// `MentionableSelectMenuComponent`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
#[doc(
    alias = "UserSelect",
    alias = "RoleSelect",
    alias = "MentionableSelect"
)]
pub struct AutoPopulatedSelect {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The text shown when nothing is selected (max 150 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<CompactString>,
    /// The entities selected by default; their number must be within `min_values` and
    /// `max_values`.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub default_values: Vec<SelectDefaultValue>,
    /// The minimum number of entities to choose (Discord's default: 1; 0-25).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_values: Option<u8>,
    /// The maximum number of entities to choose (Discord's default: 1; max 25).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_values: Option<u8>,
    /// Whether an answer is required in a modal (default `true`; ignored in messages).
    pub required: bool,
    /// Whether the menu is disabled (messages only; modals reject it).
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

impl AutoPopulatedSelect {
    /// Creates a select menu.
    ///
    /// discord.js counterpart: `UserSelectMenuBuilder` and its siblings (`@discordjs/builders`).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            placeholder: None,
            default_values: Vec::new(),
            min_values: None,
            max_values: None,
            required: true,
            disabled: false,
        }
    }
}

/// A [channel select](https://docs.discord.com/developers/components/reference#channel-select):
/// a menu of channels that Discord fills in.
///
/// discord.js counterpart: `ChannelSelectMenuComponent` / `ChannelSelectMenuBuilder`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
#[doc(alias = "ChannelSelectMenu")]
pub struct ChannelSelect {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The channel types to offer (all when empty).
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub channel_types: Vec<ChannelType>,
    /// The text shown when nothing is selected (max 150 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<CompactString>,
    /// The channels selected by default.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub default_values: Vec<SelectDefaultValue>,
    /// The minimum number of channels to choose (Discord's default: 1; 0-25).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_values: Option<u8>,
    /// The maximum number of channels to choose (Discord's default: 1; max 25).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_values: Option<u8>,
    /// Whether an answer is required in a modal (default `true`; ignored in messages).
    pub required: bool,
    /// Whether the menu is disabled (messages only; modals reject it).
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub disabled: bool,
}

impl ChannelSelect {
    /// Creates a channel select menu.
    ///
    /// discord.js counterpart: `ChannelSelectMenuBuilder` (`@discordjs/builders`).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            channel_types: Vec::new(),
            placeholder: None,
            default_values: Vec::new(),
            min_values: None,
            max_values: None,
            required: true,
            disabled: false,
        }
    }
}

/// An [entity selected by default](https://docs.discord.com/developers/components/reference#user-select-select-default-value-structure)
/// in an auto-populated select menu.
///
/// discord.js counterpart: `APISelectMenuDefaultValue`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct SelectDefaultValue {
    /// The ID of the user, role or channel.
    pub id: GenericId,
    /// What [`id`](Self::id) refers to.
    #[serde(rename = "type")]
    pub kind: SelectDefaultValueType,
}

impl SelectDefaultValue {
    /// Creates a default value.
    ///
    /// discord.js counterpart: `APISelectMenuDefaultValue` (discord-api-types).
    #[must_use]
    pub fn new(id: GenericId, kind: SelectDefaultValueType) -> Self {
        Self { id, kind }
    }
}

str_enum! {
    /// What a [`SelectDefaultValue`] refers to.
    ///
    /// discord.js counterpart: `SelectMenuDefaultValueType`.
    #[doc(alias = "SelectMenuDefaultValueType")]
    pub enum SelectDefaultValueType {
        /// A user.
        User = "user",
        /// A role.
        Role = "role",
        /// A channel.
        Channel = "channel",
    }
}

/// A [file upload](https://docs.discord.com/developers/components/reference#file-upload) in a
/// modal (inside a [label](super::Label)).
///
/// discord.js counterpart: `FileUploadComponent`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct FileUpload {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The minimum number of files (Discord's default: 1; 0-10).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_values: Option<u8>,
    /// The maximum number of files (Discord's default: 1; max 10).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_values: Option<u8>,
    /// Whether files must be uploaded before submitting (default `true`).
    pub required: bool,
    /// The [file types to accept](https://docs.discord.com/developers/reference#file-type-filtering):
    /// `image`, `video`, `audio` or extensions such as `.pdf` (max 10; all when empty).
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub file_types: Vec<CompactString>,
}

impl FileUpload {
    /// Creates a required file upload for one file of any type.
    ///
    /// discord.js counterpart: `AttachmentBuilder`.
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            min_values: None,
            max_values: None,
            required: true,
            file_types: Vec::new(),
        }
    }
}

/// A [radio group](https://docs.discord.com/developers/components/reference#radio-group) in a
/// modal: exactly one of 2-10 options.
///
/// discord.js counterpart: `RadioGroupComponent`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct RadioGroup {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The options (2-10).
    pub options: Vec<GroupOption>,
    /// Whether a choice is required to submit the modal (default `true`).
    pub required: bool,
}

impl RadioGroup {
    /// Creates a required radio group.
    ///
    /// discord.js counterpart: `APIRadioGroupComponent` (discord-api-types).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>, options: Vec<GroupOption>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            options,
            required: true,
        }
    }
}

/// A [checkbox group](https://docs.discord.com/developers/components/reference#checkbox-group)
/// in a modal: any number of 1-10 options.
///
/// discord.js counterpart: `CheckboxGroupComponent`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct CheckboxGroup {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// The options (1-10).
    pub options: Vec<GroupOption>,
    /// The minimum number of options to check (Discord's default: 1; 0-10).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_values: Option<u8>,
    /// The maximum number of options to check (Discord's default: the number of options).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_values: Option<u8>,
    /// Whether checking is required to submit the modal (default `true`).
    pub required: bool,
}

impl CheckboxGroup {
    /// Creates a required checkbox group.
    ///
    /// discord.js counterpart: `APICheckboxGroupComponent` (discord-api-types).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>, options: Vec<GroupOption>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            options,
            min_values: None,
            max_values: None,
            required: true,
        }
    }
}

/// An option of a [`RadioGroup`] or [`CheckboxGroup`] (the docs define two identical
/// structures).
///
/// discord.js counterpart: `APIRadioGroupOption` / `APICheckboxGroupOption` (discord-api-types).
#[derive(Clone, Debug, PartialEq, Eq, Serialize, serde::Deserialize)]
#[non_exhaustive]
#[doc(alias = "RadioGroupOption", alias = "CheckboxGroupOption")]
pub struct GroupOption {
    /// The developer-defined value (max 100 characters).
    pub value: CompactString,
    /// The text shown to the user (max 100 characters).
    pub label: CompactString,
    /// An additional description (max 100 characters).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<CompactString>,
    /// Whether the option is selected by default.
    #[serde(default, skip_serializing_if = "core::ops::Not::not")]
    pub default: bool,
}

impl GroupOption {
    /// Creates an option.
    ///
    /// discord.js counterpart: `APIRadioGroupOption` (discord-api-types).
    #[must_use]
    pub fn new(label: impl Into<CompactString>, value: impl Into<CompactString>) -> Self {
        Self {
            value: value.into(),
            label: label.into(),
            description: None,
            default: false,
        }
    }
}

/// A single [checkbox](https://docs.discord.com/developers/components/reference#checkbox) in a
/// modal: a yes/no choice.
///
/// discord.js counterpart: `CheckboxComponent`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct Checkbox {
    /// The component's numeric identifier (generated by Discord when not set).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    /// The developer-defined identifier (1-100 characters).
    pub custom_id: CompactString,
    /// Whether the checkbox is checked by default.
    #[serde(skip_serializing_if = "core::ops::Not::not")]
    pub default: bool,
}

impl Checkbox {
    /// Creates an unchecked checkbox.
    ///
    /// discord.js counterpart: `APICheckboxComponent` (discord-api-types).
    #[must_use]
    pub fn new(custom_id: impl Into<CompactString>) -> Self {
        Self {
            id: None,
            custom_id: custom_id.into(),
            default: false,
        }
    }
}