62 lines
1.7 KiB
Swift
62 lines
1.7 KiB
Swift
import Foundation
|
|
|
|
struct UserResponse: Codable, Identifiable, Sendable {
|
|
let id: UUID
|
|
let email: String
|
|
let status: UserStatus
|
|
let metadata: [String: AnyCodable]?
|
|
let emailVerifiedAt: Date?
|
|
let roles: [String]
|
|
let createdAt: Date
|
|
let updatedAt: Date
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id, email, status, metadata, roles
|
|
case emailVerifiedAt = "email_verified_at"
|
|
case createdAt = "created_at"
|
|
case updatedAt = "updated_at"
|
|
}
|
|
}
|
|
|
|
enum UserStatus: String, Codable, Sendable {
|
|
case pending
|
|
case active
|
|
case suspended
|
|
case deleted
|
|
}
|
|
|
|
// Helper for Any JSON values
|
|
struct AnyCodable: Codable, @unchecked Sendable {
|
|
let value: Any
|
|
|
|
init(_ value: Any) {
|
|
self.value = value
|
|
}
|
|
|
|
init(from decoder: Decoder) throws {
|
|
let container = try decoder.singleValueContainer()
|
|
if let int = try? container.decode(Int.self) {
|
|
value = int
|
|
} else if let double = try? container.decode(Double.self) {
|
|
value = double
|
|
} else if let bool = try? container.decode(Bool.self) {
|
|
value = bool
|
|
} else if let string = try? container.decode(String.self) {
|
|
value = string
|
|
} else {
|
|
value = ""
|
|
}
|
|
}
|
|
|
|
func encode(to encoder: Encoder) throws {
|
|
var container = encoder.singleValueContainer()
|
|
switch value {
|
|
case let int as Int: try container.encode(int)
|
|
case let double as Double: try container.encode(double)
|
|
case let bool as Bool: try container.encode(bool)
|
|
case let string as String: try container.encode(string)
|
|
default: try container.encode("")
|
|
}
|
|
}
|
|
}
|