forked from
smokesignal.events/smokesignal
i18n+filtering fork - fluent-templates v2
1use crate::atproto::lexicon::{
2 community::lexicon::calendar::event::EventLocation, community::lexicon::location::Address,
3};
4
5/// Checks whether location is editable based on the event's locations
6pub fn check_location_edit_status(locations: &[EventLocation]) -> LocationEditStatus {
7 if locations.is_empty() {
8 // Return editable status with a default empty address when no locations exist
9 return LocationEditStatus::Editable(Address::Current {
10 country: "".to_string(), // Default empty country
11 postal_code: None,
12 region: None,
13 locality: None,
14 street: None,
15 name: None,
16 });
17 }
18
19 if locations.len() > 1 {
20 return LocationEditStatus::MultipleLocations;
21 }
22
23 // We have exactly one location
24 match &locations[0] {
25 EventLocation::Address(address @ Address::Current { .. }) => {
26 LocationEditStatus::Editable(address.clone())
27 }
28 _ => LocationEditStatus::UnsupportedLocationType,
29 }
30}
31
32/// Represents the different states of location editability for an event
33#[derive(Debug, Clone)]
34pub enum LocationEditStatus {
35 /// Single address location that can be edited
36 Editable(Address),
37
38 /// Multiple locations present, cannot be edited through web interface
39 MultipleLocations,
40
41 /// Unsupported location type, cannot be edited through web interface
42 UnsupportedLocationType,
43
44 /// No locations present, cannot be edited through web interface
45 NoLocations,
46}
47
48impl LocationEditStatus {
49 /// Returns whether the location is editable
50 pub fn is_editable(&self) -> bool {
51 matches!(self, Self::Editable(_))
52 }
53
54 /// Returns a human-readable reason why location isn't editable
55 pub fn edit_reason(&self) -> Option<&'static str> {
56 match self {
57 Self::Editable(_) => None,
58 Self::MultipleLocations => Some("Event has multiple locations"),
59 Self::UnsupportedLocationType => Some("Event has an unsupported location type"),
60 Self::NoLocations => Some("Event has no locations"),
61 }
62 }
63}