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
//! # Option Object
//! [slack api docs 🔗]
//!
//! An object that represents a single selectable item in a
//! - [select menu 🔗],
//! - [multi-select menu 🔗],
//! - [checkbox group 🔗],
//! - [radio button group 🔗],
//! - or [overflow menu 🔗].
//!
//! [slack api docs 🔗]: https://api.slack.com/reference/block-kit/composition-objects#option
//! [select menu 🔗]: https://api.slack.com/reference/block-kit/block-elements#select
//! [multi-select menu 🔗]: https://api.slack.com/reference/block-kit/block-elements#multi_select
//! [checkbox group 🔗]: https://api.slack.com/reference/block-kit/block-elements#checkboxes
//! [radio button group 🔗]: https://api.slack.com/reference/block-kit/block-elements#radio
//! [overflow menu 🔗]: https://api.slack.com/reference/block-kit/block-elements#overflow

use std::{borrow::Cow, marker::PhantomData};

use serde::{Deserialize, Serialize};
use validator::Validate;

use super::text;
use crate::{build::*, val_helpr::ValidationResult};

/// Opt supports text::Plain and text::Mrkdwn.
#[derive(Copy,
           Clone,
           Debug,
           Deserialize,
           Hash,
           PartialEq,
           Serialize,
           Validate)]
pub struct AnyText;

/// Opt does not support urls.
#[derive(Copy,
           Clone,
           Debug,
           Deserialize,
           Hash,
           PartialEq,
           Serialize,
           Validate)]
pub struct NoUrl;

/// Opt does support urls.
#[derive(Copy,
           Clone,
           Debug,
           Deserialize,
           Hash,
           PartialEq,
           Serialize,
           Validate)]
pub struct AllowUrl;

/// # Option Object
/// [slack api docs 🔗]
///
/// An object that represents a single selectable item in a
/// - [select menu 🔗],
/// - [multi-select menu 🔗],
/// - [checkbox group 🔗],
/// - [radio button group 🔗],
/// - or [overflow menu 🔗].
///
/// [slack api docs 🔗]: https://api.slack.com/reference/block-kit/composition-objects#option
/// [select menu 🔗]: https://api.slack.com/reference/block-kit/block-elements#select
/// [multi-select menu 🔗]: https://api.slack.com/reference/block-kit/block-elements#multi_select
/// [checkbox group 🔗]: https://api.slack.com/reference/block-kit/block-elements#checkboxes
/// [radio button group 🔗]: https://api.slack.com/reference/block-kit/block-elements#radio
/// [overflow menu 🔗]: https://api.slack.com/reference/block-kit/block-elements#overflow
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize, Validate)]
pub struct Opt<'a, T = AnyText, U = NoUrl> {
  #[validate(custom = "validate::text")]
  text: text::Text,

  #[validate(length(max = 75))]
  value: Cow<'a, str>,

  #[validate(custom = "validate::desc")]
  description: Option<text::Text>,

  #[validate(custom = "validate::url")]
  url: Option<Cow<'a, str>>,

  #[serde(skip)]
  marker: PhantomData<(T, U)>,
}

impl<'a, T: Into<text::Text>, U> From<Opt<'a, T, U>> for Opt<'a, AnyText, U> {
  fn from(o: Opt<'a, T, U>) -> Self {
    Opt { text: o.text,
          value: o.value,
          description: o.description,
          url: o.url,
          marker: PhantomData::<(AnyText, U)> }
  }
}

// Constructor functions
impl<'a> Opt<'a> {
  /// Build a new option composition object
  ///
  /// # Examples
  /// ```
  /// use std::convert::TryFrom;
  ///
  /// use slack_blocks::{blocks::Actions,
  ///                    compose::Opt,
  ///                    elems::{select::Static, BlockElement},
  ///                    text};
  ///
  /// struct City {
  ///   name: String,
  ///   short_code: String,
  /// }
  ///
  /// impl City {
  ///   pub fn new(name: impl ToString, short_code: impl ToString) -> Self {
  ///     Self { name: name.to_string(),
  ///            short_code: short_code.to_string() }
  ///   }
  /// }
  ///
  /// let cities = vec![City::new("Seattle", "SEA"),
  ///                   City::new("Portland", "PDX"),
  ///                   City::new("Phoenix", "PHX")];
  ///
  /// let options =
  ///   cities.iter().map(|City { name, short_code }| {
  ///                  Opt::builder().text_plain(name).value(short_code).build()
  ///                });
  ///
  /// let select: BlockElement =
  ///   Static::builder().placeholder("Choose your favorite city!")
  ///                    .action_id("fave_city")
  ///                    .options(options)
  ///                    .build()
  ///                    .into();
  ///
  /// let block = Actions::try_from(select);
  /// ```
  pub fn builder() -> build::OptBuilderInit<'a> {
    build::OptBuilderInit::new()
  }

  /// Create an Option composition object from its label and
  /// a value to be sent back to your app when it is chosen.
  ///
  /// This returns an `Opt` that can be used by
  ///     overflow, select, and multi-select menus.
  ///     To construct an `Opt` that can be used by
  ///     radio buttons or checkboxes, see `from_mrkdwn_and_value`.
  ///
  /// # Arguments
  ///
  /// - `text` - A [text object 🔗] that defines the text shown in the option on the menu.
  ///     Overflow, select, and multi-select menus
  ///     can only use `plain_text` objects,
  ///     while radio buttons and checkboxes
  ///     can use `mrkdwn` text objects.
  ///     Maximum length for the `text` in this field is 75 characters.
  ///
  /// - `value` - The string value that will be passed to your app
  ///     when this option is chosen.
  ///     Maximum length for this field is 75 characters.
  ///
  /// [text object 🔗]: https://api.slack.com#text
  ///
  /// # Examples
  /// ```
  /// use slack_blocks::text;
  /// use slack_blocks::blocks::Block;
  /// use slack_blocks::blocks::Section;
  /// use slack_blocks::blocks::Actions;
  /// use slack_blocks::compose::Opt;
  ///
  /// let cities = vec![
  ///   ("San Francisco", "san_francisco"),
  ///   ("San Diego", "san_diego"),
  ///   ("New York City", "nyc"),
  ///   ("Phoenix", "phx"),
  ///   ("Boston", "boston"),
  ///   ("Seattle", "seattle"),
  /// ]
  ///     .into_iter()
  ///     .map(|(title, short_code)| Opt::from_plain_text_and_value(title, short_code))
  ///     .collect::<Vec<_>>();
  ///
  /// let blocks: Vec<Block> = vec![
  ///   Section::from_text(text::Plain::from("Choose your favorite city...")).into(),
  ///   Actions::from_action_elements(vec![]).into() // TODO: add overflow to this example once it exists
  /// ];
  ///
  /// // < send block to slack's API >
  /// ```
  #[deprecated(since = "0.15.0", note = "Use Opt::builder instead")]
  pub fn from_plain_text_and_value(text: impl Into<text::Plain>,
                                   value: impl Into<Cow<'a, str>>)
                                   -> Opt<'a, text::Plain, NoUrl> {
    Opt { text: text.into().into(),
          value: value.into(),
          description: None,
          url: None,
          marker: std::marker::PhantomData }
  }

  /// Create an Option composition object from its label and
  /// a value to be sent back to your app when it is chosen.
  ///
  /// This returns an `Opt` that can be used by
  ///     radio buttons or checkboxes.
  ///     To construct an `Opt` that can be used by
  ///     overflow, select, and multi-select menus,
  ///     see `from_plain_text_and_value`.
  ///
  /// # Arguments
  ///
  /// - `text` - A [text object 🔗] that defines the text shown in the option on the menu.
  ///     Overflow, select, and multi-select menus
  ///     can only use `plain_text` objects,
  ///     while radio buttons and checkboxes
  ///     can use `mrkdwn` text objects.
  ///     Maximum length for the `text` in this field is 75 characters.
  ///
  /// - `value` - The string value that will be passed to your app
  ///     when this option is chosen.
  ///     Maximum length for this field is 75 characters.
  ///
  /// [text object 🔗]: https://api.slack.com#text
  ///
  /// # Examples
  /// ```
  /// use slack_blocks::text;
  /// use slack_blocks::blocks::Block;
  /// use slack_blocks::blocks::Section;
  /// use slack_blocks::blocks::Actions;
  /// use slack_blocks::compose::Opt;
  ///
  /// let options = vec![
  ///     "1",
  ///     "2",
  ///     "3",
  ///     "4",
  ///     "5",
  /// ]
  ///     .into_iter()
  ///     .map(|num| Opt::from_mrkdwn_and_value(num, num))
  ///     .collect::<Vec<_>>();
  ///
  /// let blocks: Vec<Block> = vec![
  ///   Section::from_text(text::Plain::from("On a scale from 1 to 5...")).into(),
  ///   Actions::from_action_elements(vec![]).into() // TODO: add radio buttons to this example once it exists
  /// ];
  ///
  /// // < send block to slack's API >
  /// ```
  #[deprecated(since = "0.15.0", note = "Use Opt::builder instead")]
  pub fn from_mrkdwn_and_value(text: impl Into<text::Mrkdwn>,
                               value: impl Into<Cow<'a, str>>)
                               -> Opt<'a, text::Mrkdwn, NoUrl> {
    Opt { text: text.into().into(),
          value: value.into(),
          description: None,
          url: None,
          marker: std::marker::PhantomData }
  }
}

// Methods available to all specializations
impl<'a, T, U> Opt<'a, T, U> {
  /// Chainable setter method, that sets a description for this `Opt`.
  ///
  /// # Arguments
  ///
  /// - `desc` - A [`plain_text` only text object 🔗] that defines
  ///     a line of descriptive text shown below the `text` field
  ///     beside the radio button.
  ///     Maximum length for the `text` object within this field
  ///     is 75 characters.
  ///
  /// [`plain_text` only text object 🔗]: https://api.slack.com/reference/block-kit/composition-objects#text
  ///
  /// # Example
  ///
  /// ```
  /// use slack_blocks::text;
  /// use slack_blocks::blocks::Block;
  /// use slack_blocks::blocks::Section;
  /// use slack_blocks::blocks::Actions;
  /// use slack_blocks::compose::Opt;
  ///
  /// let options = vec![
  ///     ("1", "Hated it."),
  ///     ("2", "Didn't like it."),
  ///     ("3", "It was OK."),
  ///     ("4", "Liked it!"),
  ///     ("5", "New favorite!!"),
  /// ]
  ///     .into_iter()
  ///     .map(|(num, desc)| {
  ///         Opt::from_mrkdwn_and_value(num, num)
  ///             .with_description(desc)
  ///     })
  ///     .collect::<Vec<_>>();
  ///
  /// let blocks: Vec<Block> = vec![
  ///   Section::from_text(text::Plain::from("On a scale from 1 to 5...")).into(),
  ///   Actions::from_action_elements(vec![]).into() // TODO: add radio buttons to this example once it exists
  /// ];
  ///
  /// // < send block to slack's API >
  /// ```
  #[deprecated(since = "0.15.0", note = "Use Opt::builder instead")]
  pub fn with_description(mut self, desc: impl Into<text::Plain>) -> Self {
    self.description = Some(desc.into().into());
    self
  }

  /// Validate that this Option composition object
  /// agrees with Slack's model requirements
  ///
  /// # Errors
  /// - If `from_plain_text_and_value` or `from_mrkdwn_and_value`
  ///     was called with `text` longer than 75 chars
  /// - If `from_plain_text_and_value` or `from_mrkdwn_and_value`
  ///     was called with `value` longer than 75 chars
  /// - If `with_url` was called with url longer than 3000 chars
  /// - If `with_description` was called with text longer than 75 chars
  ///
  /// # Example
  /// ```
  /// use std::iter::repeat;
  ///
  /// use slack_blocks::compose::Opt;
  ///
  /// let long_string: String = repeat(' ').take(76).collect();
  ///
  /// let opt = Opt::from_plain_text_and_value("My Option", long_string);
  ///
  /// assert_eq!(true, matches!(opt.validate(), Err(_)));
  /// ```
  pub fn validate(&self) -> ValidationResult {
    Validate::validate(self)
  }
}

// Methods available only to `Opt` created from `text::Plain`
impl<'a, U> Opt<'a, text::Plain, U> {
  /// Chainable setter method, that sets a url for this `Opt`.
  ///
  /// **The `url` attribute is only available in [overflow menus 🔗]**.
  ///
  /// If you're using `url`, you'll still receive an [interaction payload 🔗]
  /// and will need to [send an acknowledgement response 🔗].
  ///
  /// # Arguments
  /// - `url` - A URL to load in the user's browser when the option is clicked.
  ///     Maximum length for this field is 3000 characters.
  ///
  /// [overflow menus 🔗]: https://api.slack.com/reference/block-kit/block-elements#overflow
  /// [interaction payload 🔗]: https://api.slack.com/interactivity/handling#payloads
  /// [send an acknowledgement response 🔗]: https://api.slack.com/interactivity/handling#acknowledgment_response
  ///
  /// # Example
  /// ```
  /// use slack_blocks::text;
  /// use slack_blocks::blocks::Block;
  /// use slack_blocks::blocks::Section;
  /// use slack_blocks::blocks::Actions;
  /// use slack_blocks::compose::Opt;
  ///
  /// let cities = vec![
  ///   ("San Francisco", "san_francisco", "https://www.sftravel.com/"),
  ///   ("San Diego", "san_diego", "https://www.sandiego.org/explore.aspx"),
  ///   ("New York City", "nyc", "https://www.nycgo.com/"),
  ///   ("Phoenix", "phx", "https://www.visitphoenix.com/"),
  ///   ("Boston", "boston", "https://www.boston.gov/visiting-boston"),
  ///   ("Seattle", "seattle", "https://visitseattle.org/"),
  /// ]
  ///     .into_iter()
  ///     .map(|(title, short_code, travel_link)| {
  ///         Opt::from_plain_text_and_value(title, short_code)
  ///             .with_url(travel_link)
  ///     })
  ///     .collect::<Vec<_>>();
  ///
  /// let blocks: Vec<Block> = vec![
  ///   Section::from_text(text::Plain::from("Choose your favorite city...")).into(),
  ///   Actions::from_action_elements(vec![]).into() // TODO: add overflow to this example once it exists
  /// ];
  ///
  /// // < send block to slack's API >
  /// ```
  #[deprecated(since = "0.15.0", note = "Use Opt::builder instead")]
  pub fn with_url(self,
                  url: impl Into<Cow<'a, str>>)
                  -> Opt<'a, text::Plain, AllowUrl> {
    Opt { text: self.text,
          value: self.value,
          description: self.description,
          url: Some(url.into()),
          marker: std::marker::PhantomData }
  }
}

/// Opt builder
pub mod build {
  use std::marker::PhantomData;

  use super::*;

  /// Required builder methods
  #[allow(non_camel_case_types)]
  pub mod method {
    /// OptBuilder.value
    #[derive(Copy, Clone, Debug)]
    pub struct value;
    /// OptBuilder.text
    #[derive(Copy, Clone, Debug)]
    pub struct text;
    /// OptBuilder.url
    #[derive(Copy, Clone, Debug)]
    pub struct url;
  }

  /// Initial state for OptBuilder
  pub type OptBuilderInit<'a> =
    OptBuilder<'a,
               RequiredMethodNotCalled<method::text>,
               RequiredMethodNotCalled<method::value>,
               OptionalMethodNotCalled<method::url>>;

  /// Option builder
  ///
  /// Allows you to construct a Option composition object safely, with compile-time checks
  /// on required setter methods.
  ///
  /// # Required Methods
  /// `Opt::build()` is only available if these methods have been called:
  ///  - `text` or `text_plain` or `text_md`
  ///  - `value`
  ///
  /// # Example
  /// ```
  /// use std::convert::TryFrom;
  ///
  /// use slack_blocks::{blocks::{Actions, Block},
  ///                    compose::Opt,
  ///                    elems::{select::Static, BlockElement}};
  /// let langs = vec![("Rust", "rs"), ("Haskell", "hs"), ("NodeJS", "node")];
  ///
  /// let langs =
  ///   langs.into_iter().map(|(name, code)| {
  ///                      Opt::builder().text_plain(name).value(code).build()
  ///                    });
  ///
  /// let select: BlockElement =
  ///   Static::builder().placeholder("Choose your favorite programming language!")
  ///                    .options(langs)
  ///                    .action_id("lang_chosen")
  ///                    .build()
  ///                    .into();
  ///
  /// let block: Block =
  ///   Actions::try_from(select).expect("actions supports select elements")
  ///                            .into();
  ///
  /// // <send block to API>
  /// ```
  #[derive(Debug)]
  pub struct OptBuilder<'a, Text, Value, Url> {
    text: Option<text::Text>,
    value: Option<Cow<'a, str>>,
    description: Option<text::Text>,
    url: Option<Cow<'a, str>>,
    state: PhantomData<(Text, Value, Url)>,
  }

  impl<T, V, U> OptBuilder<'static, T, V, U> {
    /// Construct a new OptBuilder
    pub fn new() -> OptBuilderInit<'static> {
      OptBuilderInit { text: None,
                       value: None,
                       description: None,
                       url: None,
                       state: PhantomData::<_> }
    }
  }

  impl<'a, T, V, U> OptBuilder<'a, T, V, U> {
    /// Change the marker type params to some other arbitrary marker type params
    fn cast_state<T2, V2, U2>(self) -> OptBuilder<'a, T2, V2, U2> {
      OptBuilder { text: self.text,
                   value: self.value,
                   description: self.description,
                   url: self.url,
                   state: PhantomData::<_> }
    }

    /// Set `value` (**Required**)
    ///
    /// The string value that will be passed to your app
    /// when this option is chosen.
    ///
    /// Maximum length for this field is 75 characters.
    pub fn value<S>(mut self,
                    value: S)
                    -> OptBuilder<'a, T, Set<method::value>, U>
      where S: Into<Cow<'a, str>>
    {
      self.value = Some(value.into());
      self.cast_state()
    }

    /// Set `description` (Optional)
    ///
    /// A [`plain_text` only text object 🔗] that defines
    /// a line of descriptive text shown below the `text` field
    /// beside the radio button.
    ///
    /// Maximum length for the `text` object within this field
    /// is 75 characters.
    ///
    /// [`plain_text` only text object 🔗]: https://api.slack.com/reference/block-kit/composition-objects#text
    pub fn desc<S>(mut self, desc: S) -> OptBuilder<'a, T, V, U>
      where S: Into<text::Plain>
    {
      self.description = Some(desc.into().into());
      self.cast_state()
    }
  }

  impl<'a, T, V, U> OptBuilder<'a, RequiredMethodNotCalled<T>, V, U> {
    /// Set `text` (**Required**)
    ///
    /// A [text object 🔗] that defines the text shown in the option on the menu.
    /// Overflow, select, and multi-select menus
    /// can only use `plain_text` objects,
    /// while radio buttons and checkboxes
    /// can use `mrkdwn` text objects.
    ///
    /// Maximum length for the `text` in this field is 75 characters.
    ///
    /// [text object 🔗]: https://api.slack.com#text
    pub fn text_plain<Txt>(
      self,
      text: Txt)
      -> OptBuilder<'a, Set<(method::text, text::Plain)>, V, U>
      where Txt: Into<text::Plain>
    {
      self.text(text.into())
    }

    /// Set `text` (**Required**)
    ///
    /// A [text object 🔗] that defines the text shown in the option on the menu.
    /// Overflow, select, and multi-select menus
    /// can only use `plain_text` objects,
    /// while radio buttons and checkboxes
    /// can use `mrkdwn` text objects.
    ///
    /// Maximum length for the `text` in this field is 75 characters.
    ///
    /// [text object 🔗]: https://api.slack.com#text
    pub fn text_md<Txt>(
      self,
      text: Txt)
      -> OptBuilder<'a, Set<(method::text, text::Mrkdwn)>, V, U>
      where Txt: Into<text::Mrkdwn>
    {
      self.text(text.into())
    }

    /// Set `text` (**Required**)
    ///
    /// A [text object 🔗] that defines the text shown in the option on the menu.
    /// Overflow, select, and multi-select menus
    /// can only use `plain_text` objects,
    /// while radio buttons and checkboxes
    /// can use `mrkdwn` text objects.
    ///
    /// Maximum length for the `text` in this field is 75 characters.
    ///
    /// [text object 🔗]: https://api.slack.com#text
    pub fn text<Txt>(mut self,
                     text: Txt)
                     -> OptBuilder<'a, Set<(method::text, Txt)>, V, U>
      where Txt: Into<text::Text>
    {
      self.text = Some(text.into());
      self.cast_state()
    }
  }

  impl<'a, V, U> OptBuilder<'a, Set<(method::text, text::Plain)>, V, U> {
    /// Set `url` (Optional)
    ///
    /// The URL will be loaded in the user's browser when the option is clicked.
    ///
    /// Maximum length for this field is 3000 characters.
    ///
    /// The `url` attribute is only available in [overflow menus 🔗]
    ///
    /// If you're using `url`, you'll still receive an [interaction payload 🔗]
    /// and will need to [send an acknowledgement response 🔗].
    ///
    /// [overflow menus 🔗]: https://api.slack.com/reference/block-kit/block-elements#overflow
    /// [interaction payload 🔗]: https://api.slack.com/interactivity/handling#payloads
    /// [send an acknowledgement response 🔗]: https://api.slack.com/interactivity/handling#acknowledgment_response
    pub fn url<S>(
      mut self,
      url: S)
      -> OptBuilder<'a, Set<(method::text, text::Plain)>, V, Set<method::url>>
      where S: Into<Cow<'a, str>>
    {
      self.url = Some(url.into());
      self.cast_state()
    }

    /// Flag opt as being usable in an `AllowUrl` context without setting Url explicitly.
    pub fn no_url(
      self)
      -> OptBuilder<'a, Set<(method::text, text::Plain)>, V, Set<method::url>>
    {
      self.cast_state()
    }
  }

  impl<'a>
    OptBuilder<'a,
               Set<(method::text, text::Plain)>,
               Set<method::value>,
               Set<method::url>>
  {
    /// All done building, now give me a darn option!
    ///
    /// > `no method name 'build' found for struct 'compose::opt::build::OptBuilder<...>'`?
    ///
    /// Make sure all required setter methods have been called. See docs for `OptBuilder`.
    ///
    /// ```compile_fail
    /// use slack_blocks::compose::Opt;
    ///
    /// let sel = Opt::builder().build(); // Won't compile!
    /// ```
    ///
    /// ```
    /// use slack_blocks::compose::Opt;
    ///
    /// let opt = Opt::builder().text_plain("cheese")
    ///                         .value("cheese")
    ///                         .url("https://cheese.com")
    ///                         .build();
    /// ```
    pub fn build(self) -> Opt<'a, text::Plain, AllowUrl> {
      Opt { text: self.text.unwrap(),
            value: self.value.unwrap(),
            url: self.url,
            description: self.description,
            marker: PhantomData::<_> }
    }
  }

  impl<'a, T: Into<text::Text>>
    OptBuilder<'a,
               Set<(method::text, T)>,
               Set<method::value>,
               OptionalMethodNotCalled<method::url>>
  {
    /// All done building, now give me a darn option!
    ///
    /// > `no method name 'build' found for struct 'compose::opt::build::OptBuilder<...>'`?
    ///
    /// Make sure all required setter methods have been called. See docs for `OptBuilder`.
    ///
    /// ```compile_fail
    /// use slack_blocks::compose::Opt;
    ///
    /// let sel = Opt::builder().text_plain("foo")
    ///                         .build();
    /// /*                       ^^^^^ method not found in
    ///                          `OptBuilder<'_, Set<(text, text::Plain)>, RequiredMethodNotCalled<value>>`
    /// */
    /// ```
    ///
    /// ```
    /// use slack_blocks::compose::Opt;
    ///
    /// let opt = Opt::builder().text_md("cheese").value("cheese").build();
    /// ```
    pub fn build(self) -> Opt<'a, T, NoUrl> {
      Opt { text: self.text.unwrap(),
            value: self.value.unwrap(),
            url: self.url,
            description: self.description,
            marker: PhantomData::<_> }
    }
  }
}

mod validate {
  use super::*;
  use crate::val_helpr::{below_len, ValidatorResult};

  pub(super) fn text(text: &text::Text) -> ValidatorResult {
    below_len("Option Text", 75, text.as_ref())
  }

  pub(super) fn desc(text: &text::Text) -> ValidatorResult {
    below_len("Option Description", 75, text.as_ref())
  }

  pub(super) fn url(text: &Cow<'_, str>) -> ValidatorResult {
    below_len("URL", 3000, text.as_ref())
  }
}