// Getting event details
func displayEventDetails(eventId: String) async {
do {
let event = try await ContactsService.shared.socialService.getEvent(
eventId: eventId
)
// Display basic event info
print("Event: \(event.title)")
print("Type: \(event.eventType)")
print("Created by: \(event.createdBy?.name ?? "Unknown")")
if let description = event.description {
print("Description: \(description)")
}
if let location = event.location {
print("Location: \(location)")
}
if let startTime = event.startTime {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
print("When: \(formatter.string(from: startTime))")
}
// Process metadata based on event type
if let metadata = event.metadata {
switch event.eventType {
case "photo", "post":
if let imageUrl = metadata["imageUrl"] {
print("Image: \(imageUrl)")
}
case "activity":
if let actionType = metadata["actionType"] {
print("Action: \(actionType)")
}
case "payment":
if let amount = metadata["amount"], let currency = metadata["currency"] {
print("Payment: \(amount) \(currency)")
}
case "check-in":
if let venueName = metadata["venueName"] {
print("Checked in at: \(venueName)")
}
default:
// Display all metadata for other event types
for (key, value) in metadata {
print("\(key): \(value)")
}
}
}
} catch {
print("Error retrieving event: \(error.localizedDescription)")
}
}