payfrit-beacon-ios/_backup/Models/Beacon.swift
John Pinkyfloyd 8c2320da44 Add ios-marketing idiom, iPad orientations, launch screen
- Fixed App Store icon display with ios-marketing idiom
- Added iPad orientation support for multitasking
- Added UILaunchScreen for iPad requirements
- Removed unused BLE permissions and files from build

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 19:38:11 -08:00

68 lines
2.6 KiB
Swift

import Foundation
struct Beacon: Identifiable {
let id: Int
let businessId: Int
let name: String
let uuid: String
let namespaceId: String
let instanceId: String
let isActive: Bool
let createdAt: Date?
let updatedAt: Date?
init(json: [String: Any]) {
id = Self.parseInt(json["ID"] ?? json["BeaconID"]) ?? 0
businessId = Self.parseInt(json["BusinessID"]) ?? 0
name = (json["Name"] as? String) ?? (json["BeaconName"] as? String) ?? ""
uuid = (json["UUID"] as? String) ?? (json["BeaconUUID"] as? String) ?? ""
namespaceId = (json["NamespaceId"] as? String) ?? ""
instanceId = (json["InstanceId"] as? String) ?? ""
isActive = Self.parseBool(json["IsActive"]) ?? true
createdAt = Self.parseDate(json["CreatedAt"])
updatedAt = Self.parseDate(json["UpdatedAt"])
}
/// Format the raw 32-char hex UUID into standard 8-4-4-4-12 format
var formattedUUID: String {
let clean = uuid.replacingOccurrences(of: "-", with: "").uppercased()
guard clean.count == 32 else { return uuid }
let i = clean.startIndex
let p1 = clean[i..<clean.index(i, offsetBy: 8)]
let p2 = clean[clean.index(i, offsetBy: 8)..<clean.index(i, offsetBy: 12)]
let p3 = clean[clean.index(i, offsetBy: 12)..<clean.index(i, offsetBy: 16)]
let p4 = clean[clean.index(i, offsetBy: 16)..<clean.index(i, offsetBy: 20)]
let p5 = clean[clean.index(i, offsetBy: 20)..<clean.index(i, offsetBy: 32)]
return "\(p1)-\(p2)-\(p3)-\(p4)-\(p5)"
}
// MARK: - Parse Helpers
static func parseInt(_ value: Any?) -> Int? {
guard let value = value else { return nil }
if let v = value as? Int { return v }
if let v = value as? Double { return Int(v) }
if let v = value as? NSNumber { return v.intValue }
if let v = value as? String, let i = Int(v) { return i }
return nil
}
static func parseBool(_ value: Any?) -> Bool? {
guard let value = value else { return nil }
if let b = value as? Bool { return b }
if let i = value as? Int { return i == 1 }
if let s = value as? String {
let lower = s.lowercased()
if lower == "true" || lower == "1" || lower == "yes" { return true }
if lower == "false" || lower == "0" || lower == "no" { return false }
}
return nil
}
static func parseDate(_ value: Any?) -> Date? {
guard let value = value else { return nil }
if let d = value as? Date { return d }
if let s = value as? String { return APIService.parseDate(s) }
return nil
}
}