calendar-types 0.1.0

Date, time, and string primitive types for calendar data
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
//! Types for finite set values.

use std::{convert::Infallible, fmt, str::FromStr};

use strum::{Display, EnumString};

/// A token which may be a statically known value of type `T` or else an unknown value of type
/// `S`.
///
/// The principal use of this type is to allow finite enums to be extended with arbitrary values,
/// most commonly some unknown string which is permissible but statically unknowable.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Token<T, S> {
    /// A statically known value.
    Known(T),
    /// An unknown or vendor-defined value.
    Unknown(S),
}

impl<T: Default, S> Default for Token<T, S> {
    fn default() -> Self {
        Self::Known(Default::default())
    }
}

impl<T, S> FromStr for Token<T, S>
where
    T: FromStr,
    for<'a> &'a str: Into<S>,
{
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match T::from_str(s) {
            Ok(value) => Ok(Token::Known(value)),
            Err(_) => Ok(Token::Unknown(s.into())),
        }
    }
}

impl<T, S> Token<T, S> {
    /// Like [`FromStr`], but uses a fallible conversion for the unknown variant.
    pub fn try_from_str<'a>(s: &'a str) -> Result<Self, <&'a str as TryInto<S>>::Error>
    where
        T: FromStr,
        &'a str: TryInto<S>,
    {
        match T::from_str(s) {
            Ok(value) => Ok(Token::Known(value)),
            Err(_) => s.try_into().map(Token::Unknown),
        }
    }

    /// Maps the unknown value of a `Token`, leaving known values unchanged.
    pub fn map_unknown<U>(self, f: impl FnOnce(S) -> U) -> Token<T, U> {
        match self {
            Token::Known(t) => Token::Known(t),
            Token::Unknown(s) => Token::Unknown(f(s)),
        }
    }
}

impl<T: fmt::Display, S: fmt::Display> fmt::Display for Token<T, S> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Token::Known(t) => fmt::Display::fmt(t, f),
            Token::Unknown(s) => fmt::Display::fmt(s, f),
        }
    }
}

/// A link relation from the [IANA Link Relations Registry].
///
/// [IANA Link Relations Registry]: https://www.iana.org/assignments/link-relations/
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString, Display)]
#[non_exhaustive]
#[strum(ascii_case_insensitive)]
pub enum LinkRelation {
    /// Refers to a resource that is the subject of the link's context.
    ///
    /// Source: RFC 6903, Section 2.
    #[strum(serialize = "about")]
    About,
    /// Asserts that the link target provides an access control description.
    ///
    /// Source: Web Access Control.
    #[strum(serialize = "acl")]
    Acl,
    /// Refers to a substitute for this context.
    ///
    /// Source: HTML.
    #[strum(serialize = "alternate")]
    Alternate,
    /// Refers to an AMP HTML version of the context.
    ///
    /// Source: AMP HTML.
    #[strum(serialize = "amphtml")]
    AmpHtml,
    /// Refers to a list of published APIs.
    ///
    /// Source: RFC 9727.
    #[strum(serialize = "api-catalog")]
    ApiCatalog,
    /// Refers to an appendix in a collection of resources.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "appendix")]
    Appendix,
    /// Refers to an icon for the context (synonym for `icon`).
    ///
    /// Source: Apple Web Application Configuration.
    #[strum(serialize = "apple-touch-icon")]
    AppleTouchIcon,
    /// Refers to a launch screen for the context.
    ///
    /// Source: Apple Web Application Configuration.
    #[strum(serialize = "apple-touch-startup-image")]
    AppleTouchStartupImage,
    /// Refers to a collection of records, documents, or other materials.
    ///
    /// Source: HTML 5.
    #[strum(serialize = "archives")]
    Archives,
    /// Refers to the context's author.
    ///
    /// Source: HTML.
    #[strum(serialize = "author")]
    Author,
    /// Identifies the entity that blocks access to a resource.
    ///
    /// Source: RFC 7725.
    #[strum(serialize = "blocked-by")]
    BlockedBy,
    /// Gives a permanent link to use for bookmarking purposes.
    ///
    /// Source: HTML.
    #[strum(serialize = "bookmark")]
    Bookmark,
    /// Links to a C2PA Manifest associated with the link context.
    ///
    /// Source: C2PA Technical Specification.
    #[strum(serialize = "c2pa-manifest")]
    C2paManifest,
    /// Designates the preferred version of a resource.
    ///
    /// Source: RFC 6596.
    #[strum(serialize = "canonical")]
    Canonical,
    /// Refers to a chapter in a collection of resources.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "chapter")]
    Chapter,
    /// Indicates the preferred URI for permanent citation.
    ///
    /// Source: RFC 8574.
    #[strum(serialize = "cite-as")]
    CiteAs,
    /// Represents a collection resource for the context.
    ///
    /// Source: RFC 6573.
    #[strum(serialize = "collection")]
    Collection,
    /// Refers to a compression dictionary for content encoding.
    ///
    /// Source: RFC 9842, Section 3.
    #[strum(serialize = "compression-dictionary")]
    CompressionDictionary,
    /// Refers to a table of contents.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "contents")]
    Contents,
    /// The document was later converted from the linked document.
    ///
    /// Source: RFC 7991.
    #[strum(serialize = "convertedfrom")]
    ConvertedFrom,
    /// Refers to a copyright statement for the context.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "copyright")]
    Copyright,
    /// Refers to a resource from which a submission form can be obtained.
    ///
    /// Source: RFC 6861.
    #[strum(serialize = "create-form")]
    CreateForm,
    /// Refers to the most recent item(s) in a collection.
    ///
    /// Source: RFC 5005.
    #[strum(serialize = "current")]
    Current,
    /// Links to documentation about deprecation of the context.
    ///
    /// Source: RFC 9745, Section 3.
    #[strum(serialize = "deprecation")]
    Deprecation,
    /// Refers to a resource providing information about the context.
    ///
    /// Source: Protocol for Web Description Resources (POWDER).
    #[strum(serialize = "describedby")]
    DescribedBy,
    /// The relationship asserts that resource A describes resource B.
    ///
    /// Source: RFC 6892.
    #[strum(serialize = "describes")]
    Describes,
    /// Refers to a list of patent disclosures.
    ///
    /// Source: RFC 6579.
    #[strum(serialize = "disclosure")]
    Disclosure,
    /// Indicates an origin whose resources should be resolved early.
    ///
    /// Source: HTML.
    #[strum(serialize = "dns-prefetch")]
    DnsPrefetch,
    /// Refers to a resource with byte-for-byte identical representation.
    ///
    /// Source: RFC 6249.
    #[strum(serialize = "duplicate")]
    Duplicate,
    /// Refers to a resource that can be used to edit the context.
    ///
    /// Source: RFC 5023.
    #[strum(serialize = "edit")]
    Edit,
    /// Refers to a submission form for editing the context.
    ///
    /// Source: RFC 6861.
    #[strum(serialize = "edit-form")]
    EditForm,
    /// Refers to a resource for editing media associated with the context.
    ///
    /// Source: RFC 5023.
    #[strum(serialize = "edit-media")]
    EditMedia,
    /// Identifies a potentially large related resource.
    ///
    /// Source: RFC 4287.
    #[strum(serialize = "enclosure")]
    Enclosure,
    /// Indicates a resource not part of the same site as the context.
    ///
    /// Source: HTML.
    #[strum(serialize = "external")]
    External,
    /// Refers to the furthest preceding resource in a series.
    ///
    /// Source: RFC 8288.
    #[strum(serialize = "first")]
    First,
    /// Refers to a resource providing IP geolocation information.
    ///
    /// Source: RFC 9877.
    #[strum(serialize = "geofeed")]
    Geofeed,
    /// Refers to a glossary of terms.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "glossary")]
    Glossary,
    /// Refers to context-sensitive help.
    ///
    /// Source: HTML.
    #[strum(serialize = "help")]
    Help,
    /// Refers to a resource hosted by the server.
    ///
    /// Source: RFC 6690.
    #[strum(serialize = "hosts")]
    Hosts,
    /// Refers to a hub for subscribing to updates.
    ///
    /// Source: WebSub.
    #[strum(serialize = "hub")]
    Hub,
    /// Refers to STUN/TURN server information for ICE connections.
    ///
    /// Source: RFC 9725.
    #[strum(serialize = "ice-server")]
    IceServer,
    /// Refers to an icon representing the context.
    ///
    /// Source: HTML.
    #[strum(serialize = "icon")]
    Icon,
    /// Refers to an index for the context.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "index")]
    Index,
    /// Refers to a time interval ending before the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.21.
    #[strum(serialize = "intervalafter")]
    IntervalAfter,
    /// Refers to a time interval starting after the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.22.
    #[strum(serialize = "intervalbefore")]
    IntervalBefore,
    /// Refers to a time interval contained within the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.23.
    #[strum(serialize = "intervalcontains")]
    IntervalContains,
    /// Refers to a time interval disjoint from the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.24.
    #[strum(serialize = "intervaldisjoint")]
    IntervalDisjoint,
    /// Refers to a time interval containing the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.25.
    #[strum(serialize = "intervalduring")]
    IntervalDuring,
    /// Refers to a time interval matching the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.26.
    #[strum(serialize = "intervalequals")]
    IntervalEquals,
    /// Refers to a time interval with matching end to the context.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.27.
    #[strum(serialize = "intervalfinishedby")]
    IntervalFinishedBy,
    /// Refers to a time interval finishing at the context end.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.28.
    #[strum(serialize = "intervalfinishes")]
    IntervalFinishes,
    /// Refers to a time interval encompassing the context interval.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.29.
    #[strum(serialize = "intervalin")]
    IntervalIn,
    /// Refers to a time interval starting at the context end.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.30.
    #[strum(serialize = "intervalmeets")]
    IntervalMeets,
    /// Refers to a time interval ending at the context start.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.31.
    #[strum(serialize = "intervalmetby")]
    IntervalMetBy,
    /// Refers to a time interval overlapping from before context start.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.32.
    #[strum(serialize = "intervaloverlappedby")]
    IntervalOverlappedBy,
    /// Refers to a time interval overlapping past the context end.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.33.
    #[strum(serialize = "intervaloverlaps")]
    IntervalOverlaps,
    /// Refers to a time interval with matching start to the context.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.34.
    #[strum(serialize = "intervalstartedby")]
    IntervalStartedBy,
    /// Refers to a time interval starting at the context start.
    ///
    /// Source: Time Ontology in OWL, Section 4.2.35.
    #[strum(serialize = "intervalstarts")]
    IntervalStarts,
    /// Refers to a member of a collection.
    ///
    /// Source: RFC 6573.
    #[strum(serialize = "item")]
    Item,
    /// Refers to the furthest following resource in a series.
    ///
    /// Source: RFC 8288.
    #[strum(serialize = "last")]
    Last,
    /// Points to a resource with the latest/current version.
    ///
    /// Source: RFC 5829.
    #[strum(serialize = "latest-version")]
    LatestVersion,
    /// Refers to a license associated with the context.
    ///
    /// Source: RFC 4946.
    #[strum(serialize = "license")]
    License,
    /// Refers to a set of links with the context as a participant.
    ///
    /// Source: RFC 9264.
    #[strum(serialize = "linkset")]
    Linkset,
    /// Refers to further information as a Link-based Resource Descriptor.
    ///
    /// Source: RFC 6415.
    #[strum(serialize = "lrdd")]
    Lrdd,
    /// Links to a manifest file for the context.
    ///
    /// Source: Web App Manifest.
    #[strum(serialize = "manifest")]
    Manifest,
    /// Refers to a mask applicable to the icon.
    ///
    /// Source: Creating Pinned Tab Icons (Apple).
    #[strum(serialize = "mask-icon")]
    MaskIcon,
    /// Refers to a resource about the author of the link's context.
    ///
    /// Source: Microformats rel=me.
    #[strum(serialize = "me")]
    Me,
    /// Refers to a feed of personalized media recommendations.
    ///
    /// Source: Media Feeds.
    #[strum(serialize = "media-feed")]
    MediaFeed,
    /// Indicates a fixed resource representing a prior state.
    ///
    /// Source: RFC 7089.
    #[strum(serialize = "memento")]
    Memento,
    /// Refers to the context's Micropub endpoint.
    ///
    /// Source: Micropub.
    #[strum(serialize = "micropub")]
    Micropub,
    /// Refers to a module for preemptive fetching.
    ///
    /// Source: HTML.
    #[strum(serialize = "modulepreload")]
    ModulePreload,
    /// Refers to a resource for monitoring changes.
    ///
    /// Source: RFC 5989.
    #[strum(serialize = "monitor")]
    Monitor,
    /// Refers to a resource for monitoring a group of resources.
    ///
    /// Source: RFC 5989.
    #[strum(serialize = "monitor-group")]
    MonitorGroup,
    /// Refers to the next resource in a series.
    ///
    /// Source: HTML.
    #[strum(serialize = "next")]
    Next,
    /// Refers to the immediately following archive resource.
    ///
    /// Source: RFC 5005.
    #[strum(serialize = "next-archive")]
    NextArchive,
    /// Indicates the author does not endorse the link target.
    ///
    /// Source: HTML.
    #[strum(serialize = "nofollow")]
    NoFollow,
    /// Indicates the new context should not be an auxiliary browsing context.
    ///
    /// Source: HTML.
    #[strum(serialize = "noopener")]
    NoOpener,
    /// Indicates no referrer information should be leaked.
    ///
    /// Source: HTML.
    #[strum(serialize = "noreferrer")]
    NoReferrer,
    /// Indicates the new context is an auxiliary browsing context.
    ///
    /// Source: HTML.
    #[strum(serialize = "opener")]
    Opener,
    /// Refers to a server for OpenID Authentication identity assertion.
    ///
    /// Source: OpenID Authentication 2.0.
    #[strum(serialize = "openid2.local_id")]
    OpenId2LocalId,
    /// Refers to a server accepting OpenID Authentication protocol messages.
    ///
    /// Source: OpenID Authentication 2.0.
    #[strum(serialize = "openid2.provider")]
    OpenId2Provider,
    /// Refers to an Original Resource in a Memento context.
    ///
    /// Source: RFC 7089.
    #[strum(serialize = "original")]
    Original,
    /// Refers to a P3P privacy policy.
    ///
    /// Source: The Platform for Privacy Preferences 1.0.
    #[strum(serialize = "p3pv1")]
    P3pv1,
    /// Indicates a resource where payment is accepted.
    ///
    /// Source: RFC 8288.
    #[strum(serialize = "payment")]
    Payment,
    /// Refers to a Pingback resource address.
    ///
    /// Source: Pingback 1.0.
    #[strum(serialize = "pingback")]
    Pingback,
    /// Indicates an origin to which early connection should be made.
    ///
    /// Source: HTML.
    #[strum(serialize = "preconnect")]
    Preconnect,
    /// Points to a resource with a predecessor version in history.
    ///
    /// Source: RFC 5829.
    #[strum(serialize = "predecessor-version")]
    PredecessorVersion,
    /// Indicates a resource that should be fetched early.
    ///
    /// Source: HTML.
    #[strum(serialize = "prefetch")]
    Prefetch,
    /// Indicates a resource that should be loaded early without blocking.
    ///
    /// Source: Preload.
    #[strum(serialize = "preload")]
    Preload,
    /// Indicates a resource to fetch and execute for next navigation.
    ///
    /// Source: Resource Hints.
    #[strum(serialize = "prerender")]
    Prerender,
    /// Refers to the previous resource in a series.
    ///
    /// Source: HTML.
    #[strum(serialize = "prev")]
    Prev,
    /// Refers to a preview of the context.
    ///
    /// Source: RFC 6903, Section 3.
    #[strum(serialize = "preview")]
    Preview,
    /// Refers to the previous resource in a series (synonym for `prev`).
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "previous")]
    Previous,
    /// Refers to the immediately preceding archive resource.
    ///
    /// Source: RFC 5005.
    #[strum(serialize = "prev-archive")]
    PrevArchive,
    /// Refers to a privacy policy for the context.
    ///
    /// Source: RFC 6903, Section 4.
    #[strum(serialize = "privacy-policy")]
    PrivacyPolicy,
    /// Identifies a resource conforming to a profile.
    ///
    /// Source: RFC 6906.
    #[strum(serialize = "profile")]
    Profile,
    /// Links to the publication manifest with metadata.
    ///
    /// Source: Publication Manifest.
    #[strum(serialize = "publication")]
    Publication,
    /// Used in RDAP RIR search to filter for "active" objects.
    ///
    /// Source: RFC 9910.
    #[strum(serialize = "rdap-active")]
    RdapActive,
    /// Used in RDAP to refer to child objects without children.
    ///
    /// Source: RFC 9910.
    #[strum(serialize = "rdap-bottom")]
    RdapBottom,
    /// Used in RDAP to refer to a set of child objects.
    ///
    /// Source: RFC 9910.
    #[strum(serialize = "rdap-down")]
    RdapDown,
    /// Used in RDAP to refer to the topmost parent in a hierarchy.
    ///
    /// Source: RFC 9910.
    #[strum(serialize = "rdap-top")]
    RdapTop,
    /// Used in RDAP to refer to a parent object in a hierarchy.
    ///
    /// Source: RFC 9910.
    #[strum(serialize = "rdap-up")]
    RdapUp,
    /// Identifies a related resource.
    ///
    /// Source: RFC 4287.
    #[strum(serialize = "related")]
    Related,
    /// Identifies a resource replying to the context.
    ///
    /// Source: RFC 4685.
    #[strum(serialize = "replies")]
    Replies,
    /// Identifies the root of a RESTCONF API.
    ///
    /// Source: RFC 8040.
    #[strum(serialize = "restconf")]
    Restconf,
    /// Refers to an input value for a rule instance.
    ///
    /// Source: OCF Core Optional 2.2.0.
    #[strum(serialize = "ruleinput")]
    RuleInput,
    /// Refers to a resource for searching the context.
    ///
    /// Source: OpenSearch.
    #[strum(serialize = "search")]
    Search,
    /// Refers to a section in a collection of resources.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "section")]
    Section,
    /// Conveys an identifier for the link's context.
    ///
    /// Source: RFC 4287.
    ///
    /// Note: Named `Self_` to avoid conflict with the Rust keyword.
    #[strum(serialize = "self")]
    Self_,
    /// Indicates a URI for a service document.
    ///
    /// Source: RFC 5023.
    #[strum(serialize = "service")]
    Service,
    /// Identifies a service description for machines.
    ///
    /// Source: RFC 8631.
    #[strum(serialize = "service-desc")]
    ServiceDesc,
    /// Identifies a service documentation for humans.
    ///
    /// Source: RFC 8631.
    #[strum(serialize = "service-doc")]
    ServiceDoc,
    /// Identifies general metadata for machines.
    ///
    /// Source: RFC 8631.
    #[strum(serialize = "service-meta")]
    ServiceMeta,
    /// Refers to a SIP trunking capability set document.
    ///
    /// Source: RFC 9409.
    #[strum(serialize = "sip-trunking-capability")]
    SipTrunkingCapability,
    /// Indicates a sponsored resource within the context.
    ///
    /// Source: Qualify Outbound Links (Google).
    #[strum(serialize = "sponsored")]
    Sponsored,
    /// Refers to the first resource in a collection.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "start")]
    Start,
    /// Identifies a resource representing the context's status.
    ///
    /// Source: RFC 8631.
    #[strum(serialize = "status")]
    Status,
    /// Refers to a stylesheet.
    ///
    /// Source: HTML.
    #[strum(serialize = "stylesheet")]
    Stylesheet,
    /// Refers to a subsection in a collection of resources.
    ///
    /// Source: HTML 4.01.
    #[strum(serialize = "subsection")]
    Subsection,
    /// Points to a resource with a successor version in history.
    ///
    /// Source: RFC 5829.
    #[strum(serialize = "successor-version")]
    SuccessorVersion,
    /// Identifies a resource with retirement policy information.
    ///
    /// Source: RFC 8594.
    #[strum(serialize = "sunset")]
    Sunset,
    /// Refers to a tag applying to the document.
    ///
    /// Source: HTML.
    #[strum(serialize = "tag")]
    Tag,
    /// Refers to terms of service for the context.
    ///
    /// Source: RFC 6903, Section 5.
    #[strum(serialize = "terms-of-service")]
    TermsOfService,
    /// Refers to a TimeGate for an Original Resource.
    ///
    /// Source: RFC 7089.
    #[strum(serialize = "timegate")]
    TimeGate,
    /// Refers to a TimeMap for an Original Resource.
    ///
    /// Source: RFC 7089.
    #[strum(serialize = "timemap")]
    TimeMap,
    /// Refers to a resource identifying the abstract semantic type.
    ///
    /// Source: RFC 6903, Section 6.
    #[strum(serialize = "type")]
    Type,
    /// Indicates user-generated content within the context.
    ///
    /// Source: Qualify Outbound Links (Google).
    #[strum(serialize = "ugc")]
    Ugc,
    /// Refers to a parent document in a hierarchy.
    ///
    /// Source: RFC 8288.
    #[strum(serialize = "up")]
    Up,
    /// Points to a version history resource.
    ///
    /// Source: RFC 5829.
    #[strum(serialize = "version-history")]
    VersionHistory,
    /// Identifies a source of information in the context.
    ///
    /// Source: RFC 4287.
    #[strum(serialize = "via")]
    Via,
    /// Identifies a target supporting the Webmention protocol.
    ///
    /// Source: Webmention.
    #[strum(serialize = "webmention")]
    Webmention,
    /// Points to a working copy for the resource.
    ///
    /// Source: RFC 5829.
    #[strum(serialize = "working-copy")]
    WorkingCopy,
    /// Points to the versioned resource source of a working copy.
    ///
    /// Source: RFC 5829.
    #[strum(serialize = "working-copy-of")]
    WorkingCopyOf,
}

/// A location type from the [IANA Location Types Registry].
///
/// [IANA Location Types Registry]: https://www.iana.org/assignments/location-type-registry/
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString, Display)]
#[non_exhaustive]
#[strum(ascii_case_insensitive)]
pub enum LocationType {
    /// A device used for flight (airplane, helicopter, glider, balloon, etc.).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "aircraft")]
    Aircraft,
    /// A place from which aircraft operate (airport, heliport).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "airport")]
    Airport,
    /// Enclosed area used for sports events.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "arena")]
    Arena,
    /// An automotive vehicle designed for passenger transportation.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "automobile")]
    Automobile,
    /// Business establishment for financial services.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "bank")]
    Bank,
    /// A bar or saloon.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "bar")]
    Bar,
    /// A two-wheeled pedal-propelled vehicle.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "bicycle")]
    Bicycle,
    /// A large motor vehicle designed to carry passengers.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "bus")]
    Bus,
    /// Terminal that serves bus passengers (bus depot, bus terminal).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "bus-station")]
    BusStation,
    /// A small informal establishment serving refreshments; coffee shop.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "cafe")]
    Cafe,
    /// An area used for camping, often with facilities for tents or RVs.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "campground")]
    Campground,
    /// A facility providing care services (nursing home, assisted living).
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "care-facility")]
    CareFacility,
    /// Academic classroom or lecture hall.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "classroom")]
    Classroom,
    /// Dance club, nightclub, or discotheque.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "club")]
    Club,
    /// Construction site.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "construction")]
    Construction,
    /// Convention center or exhibition hall.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "convention-center")]
    ConventionCenter,
    /// A building or housing unit that is not attached to other buildings.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "detached-unit")]
    DetachedUnit,
    /// A facility housing firefighting equipment and personnel.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "fire-station")]
    FireStation,
    /// Government building (legislative, executive, judicial, police, military).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "government")]
    Government,
    /// Hospital, hospice, medical clinic, mental institution, or doctor's office.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "hospital")]
    Hospital,
    /// Hotel, motel, inn, or other lodging establishment.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "hotel")]
    Hotel,
    /// Industrial setting (manufacturing floor, power plant).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "industrial")]
    Industrial,
    /// A location identified by a landmark or notable address.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "landmark-address")]
    LandmarkAddress,
    /// Library or other public place for literary and artistic materials.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "library")]
    Library,
    /// A two-wheeled automotive vehicle, including a scooter.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "motorcycle")]
    Motorcycle,
    /// A garage owned or operated by a municipality.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "municipal-garage")]
    MunicipalGarage,
    /// A building housing collections of artifacts or specimens.
    ///
    /// Source: NENA-STA-004.1.1-2025, NG9-1-1 CLDXF-US.
    #[strum(serialize = "museum")]
    Museum,
    /// Business setting, such as an office.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "office")]
    Office,
    /// A place without a registered place type representation.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "other")]
    Other,
    /// Outside a building, in the open air (park, city streets).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "outdoors")]
    Outdoors,
    /// A parking lot or parking garage.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "parking")]
    Parking,
    /// A public telephone booth or kiosk.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "phone-box")]
    PhoneBox,
    /// A religious site (church, chapel, mosque, shrine, synagogue, temple).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "place-of-worship")]
    PlaceOfWorship,
    /// A post office or mail facility.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "post-office")]
    PostOffice,
    /// Correctional institution (prison, penitentiary, jail, brig).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "prison")]
    Prison,
    /// Public area (shopping mall, street, park, public building, conveyance).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "public")]
    Public,
    /// Any form of public transport (aircraft, bus, train, ship).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "public-transport")]
    PublicTransport,
    /// A private or residential setting.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "residence")]
    Residence,
    /// Restaurant, coffee shop, or other public dining establishment.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "restaurant")]
    Restaurant,
    /// School or university property.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "school")]
    School,
    /// Shopping mall or area with stores accessible by common passageways.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "shopping-area")]
    ShoppingArea,
    /// Large structure for sports events, including a racetrack.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "stadium")]
    Stadium,
    /// Place where merchandise is offered for sale; a shop.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "store")]
    Store,
    /// A public thoroughfare (avenue, street, alley, lane, road, sidewalk).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "street")]
    Street,
    /// Theater, auditorium, movie theater, or similar presentation facility.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "theater")]
    Theater,
    /// A booth or station for collecting tolls.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "toll-booth")]
    TollBooth,
    /// A building housing local government offices.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "town-hall")]
    TownHall,
    /// Train, monorail, maglev, cable car, or similar conveyance.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "train")]
    Train,
    /// Terminal where trains load or unload passengers or goods.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "train-station")]
    TrainStation,
    /// An automotive vehicle for hauling goods rather than people.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "truck")]
    Truck,
    /// In a land-, water-, or aircraft that is in motion.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "underway")]
    Underway,
    /// The type of place is unknown.
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "unknown")]
    Unknown,
    /// A utility box or cabinet housing utility equipment.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "utilitybox")]
    UtilityBox,
    /// Place for storing goods (storehouse, self-storage facility).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "warehouse")]
    Warehouse,
    /// A facility for processing or transferring waste materials.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "waste-transfer-facility")]
    WasteTransferFacility,
    /// In, on, or above bodies of water (ocean, lake, river, canal).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "water")]
    Water,
    /// A facility for water treatment or distribution.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "water-facility")]
    WaterFacility,
    /// A vessel for travel on water (boat, ship).
    ///
    /// Source: RFC 4589.
    #[strum(serialize = "watercraft")]
    Watercraft,
    /// A camp providing programs and activities for youth.
    ///
    /// Source: NH Division of Emergency Services and Communications.
    #[strum(serialize = "youth-camp")]
    YouthCamp,
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::str::FromStr;

    #[test]
    fn link_relation_from_str_lowercase() {
        assert_eq!(
            LinkRelation::from_str("about").unwrap(),
            LinkRelation::About
        );
        assert_eq!(
            LinkRelation::from_str("api-catalog").unwrap(),
            LinkRelation::ApiCatalog
        );
        assert_eq!(LinkRelation::from_str("self").unwrap(), LinkRelation::Self_);
        assert_eq!(
            LinkRelation::from_str("openid2.provider").unwrap(),
            LinkRelation::OpenId2Provider
        );
    }

    #[test]
    fn link_relation_from_str_case_insensitive() {
        assert_eq!(
            LinkRelation::from_str("ABOUT").unwrap(),
            LinkRelation::About
        );
        assert_eq!(
            LinkRelation::from_str("About").unwrap(),
            LinkRelation::About
        );
        assert_eq!(
            LinkRelation::from_str("API-CATALOG").unwrap(),
            LinkRelation::ApiCatalog
        );
        assert_eq!(
            LinkRelation::from_str("Api-Catalog").unwrap(),
            LinkRelation::ApiCatalog
        );
        assert_eq!(LinkRelation::from_str("SELF").unwrap(), LinkRelation::Self_);
        assert_eq!(
            LinkRelation::from_str("OPENID2.PROVIDER").unwrap(),
            LinkRelation::OpenId2Provider
        );
    }

    #[test]
    fn link_relation_from_str_rejects_invalid() {
        assert!(LinkRelation::from_str("").is_err());
        assert!(LinkRelation::from_str("not-a-relation").is_err());
        assert!(LinkRelation::from_str("foobar").is_err());
        assert!(LinkRelation::from_str("about ").is_err());
        assert!(LinkRelation::from_str(" about").is_err());
    }

    #[test]
    fn link_relation_from_str_rejects_wrong_format() {
        // Snake case is NOT a valid alternative to kebab case
        assert!(LinkRelation::from_str("api_catalog").is_err());
        assert!(LinkRelation::from_str("cite_as").is_err());
        assert!(LinkRelation::from_str("edit_form").is_err());

        // PascalCase variant names are NOT valid
        assert!(LinkRelation::from_str("ApiCatalog").is_err());
        assert!(LinkRelation::from_str("CiteAs").is_err());
        assert!(LinkRelation::from_str("EditForm").is_err());

        // camelCase is NOT valid
        assert!(LinkRelation::from_str("apiCatalog").is_err());
        assert!(LinkRelation::from_str("citeAs").is_err());
    }

    #[test]
    fn location_type_from_str_lowercase() {
        assert_eq!(
            LocationType::from_str("aircraft").unwrap(),
            LocationType::Aircraft
        );
        assert_eq!(
            LocationType::from_str("bus-station").unwrap(),
            LocationType::BusStation
        );
        assert_eq!(
            LocationType::from_str("place-of-worship").unwrap(),
            LocationType::PlaceOfWorship
        );
        // Note: "utilitybox" has no hyphen per IANA registry
        assert_eq!(
            LocationType::from_str("utilitybox").unwrap(),
            LocationType::UtilityBox
        );
    }

    #[test]
    fn location_type_from_str_case_insensitive() {
        assert_eq!(
            LocationType::from_str("AIRCRAFT").unwrap(),
            LocationType::Aircraft
        );
        assert_eq!(
            LocationType::from_str("Aircraft").unwrap(),
            LocationType::Aircraft
        );
        assert_eq!(
            LocationType::from_str("BUS-STATION").unwrap(),
            LocationType::BusStation
        );
        assert_eq!(
            LocationType::from_str("Bus-Station").unwrap(),
            LocationType::BusStation
        );
        assert_eq!(
            LocationType::from_str("PLACE-OF-WORSHIP").unwrap(),
            LocationType::PlaceOfWorship
        );
        assert_eq!(
            LocationType::from_str("UTILITYBOX").unwrap(),
            LocationType::UtilityBox
        );
    }

    #[test]
    fn location_type_from_str_rejects_invalid() {
        assert!(LocationType::from_str("").is_err());
        assert!(LocationType::from_str("not-a-location").is_err());
        assert!(LocationType::from_str("foobar").is_err());
        assert!(LocationType::from_str("airport ").is_err());
        assert!(LocationType::from_str(" airport").is_err());
    }

    #[test]
    fn location_type_from_str_rejects_wrong_format() {
        // Snake case is NOT a valid alternative to kebab case
        assert!(LocationType::from_str("bus_station").is_err());
        assert!(LocationType::from_str("fire_station").is_err());
        assert!(LocationType::from_str("place_of_worship").is_err());

        // PascalCase variant names are NOT valid
        assert!(LocationType::from_str("BusStation").is_err());
        assert!(LocationType::from_str("FireStation").is_err());
        assert!(LocationType::from_str("PlaceOfWorship").is_err());

        // camelCase is NOT valid
        assert!(LocationType::from_str("busStation").is_err());
        assert!(LocationType::from_str("fireStation").is_err());

        // "utility-box" with hyphen is NOT valid (registry uses "utilitybox")
        assert!(LocationType::from_str("utility-box").is_err());
    }
}