ifc-resource 0.2.0

Construction resources: labour, equipment, material, crew, subcontract.
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
//! Schema-checked, transaction-staged resource authoring.

use std::collections::HashSet;

use ifc_model::{Budget, Entity, EntityId, Model, Transaction, Value};
use ifc_schema::{ifc4, Schema, TypeKind};

use crate::author::draft::{AllocationDraft, NestingDraft, ResourceDraft, ResourceTimeDraft};
use crate::error::{ResourceError, ResourceResult};
use crate::view::validate_object_assignment;
use crate::{ResourceKind, ResourceView};

/// Transaction-staged writer for the bounded IFC4 resource slice.
///
/// Every `create_*` method validates the draft against the bundled schema
/// and cross-attribute IFC rules before staging it, then commits through a
/// single-entity `ifc_model::Transaction`.
pub struct ResourceEditor<'m> {
    model: &'m mut Model,
    pub(crate) schema: &'static Schema,
}

impl<'m> ResourceEditor<'m> {
    /// Opens an editor for `model`, verifying it declares a supported
    /// resource schema (IFC4 ADD2 TC1 or IFC4X3 ADD2).
    pub fn for_model(model: &'m mut Model) -> ResourceResult<Self> {
        ResourceView::for_model(model)?;
        Ok(Self {
            model,
            schema: ifc4(),
        })
    }

    pub(crate) fn validate_new_global_id(&self, value: &str) -> ResourceResult<()> {
        validate_global_id(value)?;
        for (id, entity) in self.model.iter() {
            let Some(slot) = self
                .schema
                .attribute_names(&entity.type_name)
                .iter()
                .position(|name| name.eq_ignore_ascii_case("GlobalId"))
            else {
                continue;
            };
            if entity
                .attributes
                .get(slot)
                .is_some_and(|stored| matches!(stored.unwrap_typed(), Value::Text(stored) if stored.as_ref() == value))
            {
                return Err(ResourceError::SemanticViolation {
                    entity: Some(id),
                    rule: "IfcRoot.GlobalId must be unique in the model",
                });
            }
        }
        Ok(())
    }

    /// Commits a `ResourceDraft` as a new concrete `IfcConstructionResource`
    /// occurrence, failing if `USERDEFINED` is authored without
    /// `ObjectType`, or if `Usage`/`BaseCosts`/`BaseQuantity` reference
    /// entities of the wrong type.
    pub fn create_resource(&mut self, draft: ResourceDraft<'_>) -> ResourceResult<EntityId> {
        self.validate_new_global_id(draft.global_id)?;
        let entity_type = resource_entity_type(draft.kind);
        if let Some(value) = draft.predefined_type {
            validate_enum(self.schema, entity_type, "PredefinedType", value)?;
            if value == "USERDEFINED"
                && draft
                    .object_type
                    .is_none_or(|value| value.trim().is_empty())
            {
                return Err(ResourceError::SemanticViolation {
                    entity: None,
                    rule: "USERDEFINED_REQUIRES_OBJECT_TYPE",
                });
            }
        }
        if let Some(usage) = draft.usage {
            self.check_reference(usage, "Usage", "IfcResourceTime", usage)?;
        }
        for cost in &draft.base_costs {
            self.check_reference(*cost, "BaseCosts", "IfcAppliedValue", *cost)?;
        }
        if let Some(quantity) = draft.base_quantity {
            self.check_reference(quantity, "BaseQuantity", "IfcPhysicalQuantity", quantity)?;
        }

        let base_costs = (!draft.base_costs.is_empty()).then(|| refs(&draft.base_costs));
        let entity = build_entity(
            self.schema,
            entity_type,
            &[
                ("GlobalId", Some(text(draft.global_id))),
                ("Name", draft.name.map(text)),
                ("ObjectType", draft.object_type.map(text)),
                ("Identification", draft.identification.map(text)),
                ("LongDescription", draft.long_description.map(text)),
                ("Usage", draft.usage.map(Value::Ref)),
                ("BaseCosts", base_costs),
                ("BaseQuantity", draft.base_quantity.map(Value::Ref)),
                (
                    "PredefinedType",
                    draft.predefined_type.map(|value| Value::Enum(value.into())),
                ),
            ],
        )?;
        self.commit_create(entity)
    }

    /// Commits a `ResourceDraft` as an `IfcTypeResource` subtype.
    ///
    /// The type counterpart of [`ResourceEditor::create_resource`]:
    /// the shared definition several occurrences point at. The draft is
    /// reused because the two differ by one attribute, `Usage`, which
    /// belongs to the occurrence and is refused here rather than
    /// silently dropped.
    ///
    /// `PredefinedType` is required on every resource type in the
    /// schema, unlike on the occurrence where it is optional.
    ///
    /// # Errors
    ///
    /// Refuses a duplicate or malformed `GlobalId`, a missing or
    /// unknown `PredefinedType`, a `USERDEFINED` type with no
    /// `ObjectType` to name it, a `Usage` reference, and any
    /// `BaseCosts` or `BaseQuantity` reference of the wrong type.
    pub fn create_resource_type(&mut self, draft: ResourceDraft<'_>) -> ResourceResult<EntityId> {
        self.validate_new_global_id(draft.global_id)?;
        let entity_type = resource_type_entity_type(draft.kind);
        let Some(predefined_type) = draft.predefined_type else {
            return Err(ResourceError::SemanticViolation {
                entity: None,
                rule: "RESOURCE_TYPE_REQUIRES_PREDEFINED_TYPE",
            });
        };
        validate_enum(self.schema, entity_type, "PredefinedType", predefined_type)?;
        if predefined_type == "USERDEFINED"
            && draft
                .object_type
                .is_none_or(|value| value.trim().is_empty())
        {
            return Err(ResourceError::SemanticViolation {
                entity: None,
                rule: "USERDEFINED_REQUIRES_OBJECT_TYPE",
            });
        }
        if draft.usage.is_some() {
            return Err(ResourceError::SemanticViolation {
                entity: None,
                rule: "RESOURCE_TYPE_HAS_NO_USAGE",
            });
        }
        for cost in &draft.base_costs {
            self.check_reference(*cost, "BaseCosts", "IfcAppliedValue", *cost)?;
        }
        if let Some(quantity) = draft.base_quantity {
            self.check_reference(quantity, "BaseQuantity", "IfcPhysicalQuantity", quantity)?;
        }

        let base_costs = (!draft.base_costs.is_empty()).then(|| refs(&draft.base_costs));
        let entity = build_entity(
            self.schema,
            entity_type,
            &[
                ("GlobalId", Some(text(draft.global_id))),
                ("Name", draft.name.map(text)),
                ("ApplicableOccurrence", draft.object_type.map(text)),
                ("Identification", draft.identification.map(text)),
                ("LongDescription", draft.long_description.map(text)),
                ("BaseCosts", base_costs),
                ("BaseQuantity", draft.base_quantity.map(Value::Ref)),
                ("PredefinedType", Some(Value::Enum(predefined_type.into()))),
            ],
        )?;
        self.commit_create(entity)
    }

    /// Commits a `ResourceTimeDraft` as a new `IfcResourceTime`, failing if
    /// any ratio attribute is non-finite or not strictly positive.
    pub fn create_time(&mut self, draft: ResourceTimeDraft<'_>) -> ResourceResult<EntityId> {
        for (attribute, value) in [
            ("ScheduleUsage", draft.schedule_usage),
            ("ActualUsage", draft.actual_usage),
            ("RemainingUsage", draft.remaining_usage),
            ("Completion", draft.completion),
        ] {
            if value.is_some_and(|value| !value.is_finite() || value <= 0.0) {
                return Err(ResourceError::InvalidDraft {
                    entity_type: "IfcResourceTime",
                    attribute,
                    expected: "finite positive ratio",
                });
            }
        }
        let entity = build_entity(
            self.schema,
            "IfcResourceTime",
            &[
                ("Name", draft.name.map(text)),
                ("ScheduleWork", draft.schedule_work.map(text)),
                ("ScheduleUsage", draft.schedule_usage.map(Value::Real)),
                ("ScheduleStart", draft.schedule_start.map(text)),
                ("ScheduleFinish", draft.schedule_finish.map(text)),
                ("IsOverAllocated", draft.is_over_allocated.map(Value::Bool)),
                ("StatusTime", draft.status_time.map(text)),
                ("ActualWork", draft.actual_work.map(text)),
                ("ActualUsage", draft.actual_usage.map(Value::Real)),
                ("ActualStart", draft.actual_start.map(text)),
                ("ActualFinish", draft.actual_finish.map(text)),
                ("RemainingWork", draft.remaining_work.map(text)),
                ("RemainingUsage", draft.remaining_usage.map(Value::Real)),
                ("Completion", draft.completion.map(Value::Real)),
            ],
        )?;
        self.commit_create(entity)
    }

    /// Commits an `AllocationDraft` as a new `IfcRelAssignsToResource`,
    /// failing if `RelatedObjects` is empty, repeats a target, includes the
    /// resource itself, or references entities the `RelatedObjectsType`
    /// does not permit.
    pub fn create_allocation(&mut self, draft: AllocationDraft<'_>) -> ResourceResult<EntityId> {
        self.validate_new_global_id(draft.global_id)?;
        self.check_reference_select(
            draft.resource,
            "RelatingResource",
            "IfcResourceSelect",
            &["IfcResource", "IfcTypeResource"],
            draft.resource,
        )?;
        validate_required_unique(draft.resource, "RelatedObjects", &draft.related_objects)?;
        if let Some(category) = draft.related_objects_type {
            validate_enum(
                self.schema,
                "IfcRelAssignsToResource",
                "RelatedObjectsType",
                category,
            )?;
        }
        for target in &draft.related_objects {
            self.check_reference(
                draft.resource,
                "RelatedObjects",
                "IfcObjectDefinition",
                *target,
            )?;
            if *target == draft.resource {
                return Err(ResourceError::SemanticViolation {
                    entity: None,
                    rule: "RESOURCE_ASSIGNMENT_NO_SELF_REFERENCE",
                });
            }
        }
        validate_object_assignment(
            self.model,
            self.schema,
            None,
            draft.related_objects_type,
            &draft.related_objects,
        )?;
        let entity = build_entity(
            self.schema,
            "IfcRelAssignsToResource",
            &[
                ("GlobalId", Some(text(draft.global_id))),
                ("Name", draft.name.map(text)),
                ("Description", draft.description.map(text)),
                ("RelatedObjects", Some(refs(&draft.related_objects))),
                (
                    "RelatedObjectsType",
                    draft
                        .related_objects_type
                        .map(|value| Value::Enum(value.into())),
                ),
                ("RelatingResource", Some(Value::Ref(draft.resource))),
            ],
        )?;
        self.commit_create(entity)
    }

    /// Commits a `NestingDraft` as a new `IfcRelNests`, failing if
    /// `RelatedObjects` is empty, repeats a target, includes the parent
    /// itself, names a child that already has a resource parent, or would
    /// introduce a nesting cycle.
    pub fn create_nesting(&mut self, draft: NestingDraft<'_>) -> ResourceResult<EntityId> {
        self.validate_new_global_id(draft.global_id)?;
        self.check_reference(
            draft.parent,
            "RelatingObject",
            "IfcConstructionResource",
            draft.parent,
        )?;
        validate_required_unique(draft.parent, "RelatedObjects", &draft.children)?;
        for child in &draft.children {
            self.check_reference(
                draft.parent,
                "RelatedObjects",
                "IfcConstructionResource",
                *child,
            )?;
            if *child == draft.parent {
                return Err(ResourceError::SemanticViolation {
                    entity: None,
                    rule: "RESOURCE_NESTING_NO_SELF_REFERENCE",
                });
            }
        }
        {
            let view = ResourceView::new(self.model, self.schema)?;
            for child in &draft.children {
                if view.parent_resource(*child)?.is_some() {
                    return Err(ResourceError::SemanticViolation {
                        entity: Some(*child),
                        rule: "IfcObject.Nests permits at most one resource parent",
                    });
                }
                if view
                    .descendants(*child, Budget::DEFAULT)?
                    .contains(&draft.parent)
                {
                    return Err(ResourceError::SemanticViolation {
                        entity: Some(*child),
                        rule: "resource nesting must remain acyclic",
                    });
                }
            }
        }
        let entity = build_entity(
            self.schema,
            "IfcRelNests",
            &[
                ("GlobalId", Some(text(draft.global_id))),
                ("Name", draft.name.map(text)),
                ("Description", draft.description.map(text)),
                ("RelatingObject", Some(Value::Ref(draft.parent))),
                ("RelatedObjects", Some(refs(&draft.children))),
            ],
        )?;
        self.commit_create(entity)
    }

    pub(crate) fn check_reference(
        &self,
        owner: EntityId,
        attribute: &'static str,
        expected: &'static str,
        target: EntityId,
    ) -> ResourceResult<()> {
        self.check_reference_select(owner, attribute, expected, &[expected], target)
    }

    pub(crate) fn check_reference_select(
        &self,
        owner: EntityId,
        attribute: &'static str,
        expected: &'static str,
        members: &[&str],
        target: EntityId,
    ) -> ResourceResult<()> {
        let entity = self
            .model
            .get(target)
            .ok_or(ResourceError::DanglingReference {
                entity: owner,
                attribute,
                target,
            })?;
        if !members
            .iter()
            .any(|member| self.schema.is_a(&entity.type_name, member))
        {
            return Err(ResourceError::WrongReferenceType {
                entity: owner,
                attribute,
                target,
                expected,
                actual: entity.type_name.to_string(),
            });
        }
        Ok(())
    }

    pub(crate) fn commit_create(&mut self, entity: Entity) -> ResourceResult<EntityId> {
        let mut transaction = Transaction::new(self.model);
        let expected = transaction.revision();
        let id = transaction.create(entity);
        transaction
            .commit(self.model)
            .map_err(|_| ResourceError::TransactionConflict {
                expected,
                actual: self.model.revision(),
            })?;
        Ok(id)
    }
}

fn resource_entity_type(kind: ResourceKind) -> &'static str {
    match kind {
        ResourceKind::Labor => "IfcLaborResource",
        ResourceKind::Equipment => "IfcConstructionEquipmentResource",
        ResourceKind::Crew => "IfcCrewResource",
        ResourceKind::Material => "IfcConstructionMaterialResource",
        ResourceKind::Product => "IfcConstructionProductResource",
        ResourceKind::Subcontract => "IfcSubContractResource",
    }
}

/// The `IfcTypeResource` subtype paired with each occurrence kind.
///
/// Each occurrence resource has exactly one type counterpart, so the
/// mapping lives next to [`resource_entity_type`] rather than being
/// derived by string surgery on the occurrence name.
fn resource_type_entity_type(kind: ResourceKind) -> &'static str {
    match kind {
        ResourceKind::Labor => "IfcLaborResourceType",
        ResourceKind::Equipment => "IfcConstructionEquipmentResourceType",
        ResourceKind::Crew => "IfcCrewResourceType",
        ResourceKind::Material => "IfcConstructionMaterialResourceType",
        ResourceKind::Product => "IfcConstructionProductResourceType",
        ResourceKind::Subcontract => "IfcSubContractResourceType",
    }
}

pub(crate) fn build_entity(
    schema: &Schema,
    entity_type: &'static str,
    values: &[(&'static str, Option<Value>)],
) -> ResourceResult<Entity> {
    if schema.entity(entity_type).is_none() {
        return Err(ResourceError::InvalidDraft {
            entity_type,
            attribute: "<entity>",
            expected: "entity declared by IFC4",
        });
    }
    let attribute_names = schema.attribute_names(entity_type);
    let mut attributes = vec![Value::Null; attribute_names.len()];
    for (name, value) in values {
        if let Some(value) = value {
            let slot = attribute_names
                .iter()
                .position(|candidate| candidate.eq_ignore_ascii_case(name))
                .ok_or(ResourceError::InvalidDraft {
                    entity_type,
                    attribute: name,
                    expected: "attribute declared by IFC4",
                })?;
            attributes[slot] = value.clone();
        }
    }
    Ok(Entity::new(entity_type, attributes))
}

pub(crate) fn validate_enum(
    schema: &Schema,
    entity_type: &'static str,
    attribute: &'static str,
    value: &str,
) -> ResourceResult<()> {
    let declared = schema
        .attributes(entity_type)
        .iter()
        .find(|candidate| candidate.name.eq_ignore_ascii_case(attribute))
        .and_then(|attribute| schema.type_def(&attribute.type_name))
        .is_some_and(|definition| {
            matches!(&definition.kind, TypeKind::Enumeration(values) if values.iter().any(|member| member == value))
        });
    if !declared {
        return Err(ResourceError::InvalidEnumeration {
            entity: None,
            attribute,
            value: value.to_owned(),
        });
    }
    Ok(())
}

fn validate_required_unique(
    owner: EntityId,
    attribute: &'static str,
    values: &[EntityId],
) -> ResourceResult<()> {
    if values.is_empty() {
        return Err(ResourceError::InvalidCardinality {
            entity: owner,
            attribute,
            minimum: 1,
            actual: 0,
        });
    }
    let mut unique = HashSet::with_capacity(values.len());
    for value in values {
        if !unique.insert(*value) {
            return Err(ResourceError::DuplicateReference {
                entity: owner,
                attribute,
                target: *value,
            });
        }
    }
    Ok(())
}

fn validate_global_id(value: &str) -> ResourceResult<()> {
    if value.len() != 22
        || !matches!(value.as_bytes().first(), Some(b'0'..=b'3'))
        || !value
            .bytes()
            .all(|byte| byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'$')
    {
        return Err(ResourceError::InvalidGlobalId);
    }
    Ok(())
}

pub(crate) fn text(value: &str) -> Value {
    Value::Text(value.into())
}

pub(crate) fn refs(values: &[EntityId]) -> Value {
    Value::List(values.iter().copied().map(Value::Ref).collect())
}

/// Draft for one `IfcAppliedValue`.
#[derive(Debug, Clone, Copy, Default)]
pub struct AppliedValueDraft<'a> {
    /// `Name`.
    pub name: Option<&'a str>,
    /// `Description`.
    pub description: Option<&'a str>,
    /// `AppliedValue`, an `IfcAppliedValueSelect` reference.
    pub applied_value: Option<EntityId>,
    /// `UnitBasis`, the `IfcMeasureWithUnit` the value is quoted per.
    pub unit_basis: Option<EntityId>,
    /// `ApplicableDate`, an ISO 8601 date written as given.
    pub applicable_date: Option<&'a str>,
    /// `FixedUntilDate`, an ISO 8601 date written as given.
    pub fixed_until_date: Option<&'a str>,
    /// `Category`.
    pub category: Option<&'a str>,
    /// `Condition`.
    pub condition: Option<&'a str>,
    /// `ArithmeticOperator`, an `IfcArithmeticOperatorEnum` token.
    pub arithmetic_operator: Option<&'a str>,
}

impl ResourceEditor<'_> {
    /// Create an `IfcAppliedValue`, optionally composed from components.
    ///
    /// An applied value is a cost-like quantity: a value, the unit basis
    /// it is quoted per, and the dates it applies between. It may instead
    /// be *composed*, combining `components` with an arithmetic operator.
    ///
    /// The schema states no WHERE rule tying the two together, but a
    /// composition without an operator does not say how to combine its
    /// parts, and an operator without components has nothing to combine;
    /// both are refused rather than written for a reader to guess at.
    ///
    /// `Components` is `LIST [1:?] OF IfcAppliedValue`, so an empty list
    /// is left absent rather than written as `()`, which would satisfy
    /// the type and break the bound.
    ///
    /// # Errors
    ///
    /// Refuses an `arithmetic_operator` the target schema does not
    /// declare, an operator/components pair where only one side is
    /// present, a component that is not an `IfcAppliedValue`, and an
    /// `applied_value` outside `IfcAppliedValueSelect`.
    pub fn create_applied_value(
        &mut self,
        draft: AppliedValueDraft<'_>,
        components: &[EntityId],
    ) -> ResourceResult<EntityId> {
        const ENTITY: &str = "IfcAppliedValue";
        if let Some(operator) = draft.arithmetic_operator {
            validate_enum(self.schema, ENTITY, "ArithmeticOperator", operator)?;
        }
        if draft.arithmetic_operator.is_some() == components.is_empty() {
            return Err(ResourceError::SemanticViolation {
                entity: None,
                rule: "ArithmeticOperator and Components are stated together",
            });
        }
        if let Some(value) = draft.applied_value {
            self.check_reference_select(
                value,
                "AppliedValue",
                "IfcAppliedValueSelect",
                &[
                    "IfcMeasureWithUnit",
                    "IfcMonetaryMeasure",
                    "IfcRatioMeasure",
                    "IfcReference",
                ],
                value,
            )?;
        }
        if let Some(basis) = draft.unit_basis {
            self.check_reference(basis, "UnitBasis", "IfcMeasureWithUnit", basis)?;
        }
        for component in components {
            self.check_reference(*component, "Components", ENTITY, *component)?;
        }

        let entity = build_entity(
            self.schema,
            ENTITY,
            &[
                ("Name", draft.name.map(text)),
                ("Description", draft.description.map(text)),
                ("AppliedValue", draft.applied_value.map(Value::Ref)),
                ("UnitBasis", draft.unit_basis.map(Value::Ref)),
                ("ApplicableDate", draft.applicable_date.map(text)),
                ("FixedUntilDate", draft.fixed_until_date.map(text)),
                ("Category", draft.category.map(text)),
                ("Condition", draft.condition.map(text)),
                ("ArithmeticOperator", draft.arithmetic_operator.map(enum_of)),
                (
                    "Components",
                    (!components.is_empty()).then(|| refs(components)),
                ),
            ],
        )?;
        self.commit_create(entity)
    }
}

/// An enum token as a value.
fn enum_of(token: &str) -> Value {
    Value::Enum(std::sync::Arc::from(token.to_ascii_uppercase()))
}