specta-swift 0.0.3

Export your Rust types to Swift
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
633
634
635
636
637
638
639
640
// This file has been generated by Specta. DO NOT EDIT.
import Foundation

// MARK: - Duration Helper
/// Helper struct to decode Rust Duration format {"secs": u64, "nanos": u32}
public struct RustDuration: Codable {
    public let secs: UInt64
    public let nanos: UInt32
    
    public var timeInterval: TimeInterval {
        return Double(secs) + Double(nanos) / 1_000_000_000.0
    }
}

// MARK: - Generated Types

/// Admin level enum
public enum AdminLevel: Codable {
    case junior
    case senior
    case lead
    case director
}

/// API response wrapper
public struct ApiResponse<T, E>: Codable {
    public let data: T?
    public let error: E?
    public let status: ResponseStatus
    public let metadata: ResponseMetadata
}

/// File attachment
public struct Attachment: Codable {
    public let id: String
    public let filename: String
    public let size: UInt64
    public let mimeType: String
    public let uploadedAt: String
    public let uploadedBy: UInt32

    private enum CodingKeys: String, CodingKey {
        case id = "id"
        case filename = "filename"
        case size = "size"
        case mimeType = "mime_type"
        case uploadedAt = "uploaded_at"
        case uploadedBy = "uploaded_by"
    }
}

/// Data sharing settings
public struct DataSharing: Codable {
    public let analytics: Bool
    public let marketing: Bool
    public let thirdParty: Bool
    public let research: Bool

    private enum CodingKeys: String, CodingKey {
        case analytics = "analytics"
        case marketing = "marketing"
        case thirdParty = "third_party"
        case research = "research"
    }
}

/// Display settings
public struct DisplaySettings: Codable {
    public let itemsPerPage: UInt32
    public let dateFormat: String
    public let timeFormat: String
    public let currency: String
    public let compactMode: Bool

    private enum CodingKeys: String, CodingKey {
        case itemsPerPage = "items_per_page"
        case dateFormat = "date_format"
        case timeFormat = "time_format"
        case currency = "currency"
        case compactMode = "compact_mode"
    }
}

/// Health status enum
public enum HealthStatus: Codable {
    case healthy
    case degraded
    case unhealthy
    case unknown
}

/// Notification frequency enum
public enum NotificationFrequency: Codable {
    case immediate
    case hourly
    case daily
    case weekly
    case never
}

/// Notification settings
public struct NotificationSettings: Codable {
    public let emailEnabled: Bool
    public let pushEnabled: Bool
    public let smsEnabled: Bool
    public let desktopEnabled: Bool
    public let frequency: NotificationFrequency

    private enum CodingKeys: String, CodingKey {
        case emailEnabled = "email_enabled"
        case pushEnabled = "push_enabled"
        case smsEnabled = "sms_enabled"
        case desktopEnabled = "desktop_enabled"
        case frequency = "frequency"
    }
}

/// Pagination information
public struct PaginationInfo: Codable {
    public let page: UInt32
    public let perPage: UInt32
    public let totalPages: UInt32
    public let totalItems: UInt64
    public let hasNext: Bool
    public let hasPrev: Bool

    private enum CodingKeys: String, CodingKey {
        case page = "page"
        case perPage = "per_page"
        case totalPages = "total_pages"
        case totalItems = "total_items"
        case hasNext = "has_next"
        case hasPrev = "has_prev"
    }
}

/// Priority enum (string enum)
public enum Priority: Codable {
    case low
    case medium
    case high
    case critical
    case emergency
}

/// Privacy settings
public struct PrivacySettings: Codable {
    public let profileVisibility: Visibility
    public let activityVisibility: Visibility
    public let dataSharing: DataSharing

    private enum CodingKeys: String, CodingKey {
        case profileVisibility = "profile_visibility"
        case activityVisibility = "activity_visibility"
        case dataSharing = "data_sharing"
    }
}

/// Response metadata
public struct ResponseMetadata: Codable {
    public let requestId: String
    public let timestamp: String
    public let processingTime: RustDuration
    public let version: String
    public let pagination: PaginationInfo?

    private enum CodingKeys: String, CodingKey {
        case requestId = "request_id"
        case timestamp = "timestamp"
        case processingTime = "processing_time"
        case version = "version"
        case pagination = "pagination"
    }
}

/// Response status enum
public enum ResponseStatus: Codable {
    case success
    case partialSuccess
    case error
    case validationError
    case authenticationError
    case authorizationError
    case notFound
    case rateLimited
}

/// Review comment
public struct ReviewComment: Codable {
    public let id: UInt32
    public let author: UInt32
    public let content: String
    public let createdAt: String
    public let updatedAt: String
    public let isResolved: Bool
    public let parentComment: UInt32?
    public let attachments: [Attachment]

    private enum CodingKeys: String, CodingKey {
        case id = "id"
        case author = "author"
        case content = "content"
        case createdAt = "created_at"
        case updatedAt = "updated_at"
        case isResolved = "is_resolved"
        case parentComment = "parent_comment"
        case attachments = "attachments"
    }
}

/// Service status
public struct ServiceStatus: Codable {
    public let name: String
    public let status: HealthStatus
    public let responseTime: RustDuration
    public let lastCheck: String
    public let errorCount: UInt32

    private enum CodingKeys: String, CodingKey {
        case name = "name"
        case status = "status"
        case responseTime = "response_time"
        case lastCheck = "last_check"
        case errorCount = "error_count"
    }
}

/// Subtask with timing information
public struct SubTask: Codable {
    public let id: UInt32
    public let title: String
    public let description: String?
    public let status: SubTaskStatus
    public let estimatedDuration: RustDuration
    public let actualDuration: RustDuration?
    public let assignee: UInt32?
    public let createdAt: String
    public let completedAt: String?

    private enum CodingKeys: String, CodingKey {
        case id = "id"
        case title = "title"
        case description = "description"
        case status = "status"
        case estimatedDuration = "estimated_duration"
        case actualDuration = "actual_duration"
        case assignee = "assignee"
        case createdAt = "created_at"
        case completedAt = "completed_at"
    }
}

/// Subtask status (simple enum)
public enum SubTaskStatus: Codable {
    case pending
    case inProgress
    case completed
    case skipped
}

/// System health information
public struct SystemHealth: Codable {
    public let status: HealthStatus
    public let uptime: RustDuration
    public let lastCheck: String
    public let services: [ServiceStatus]
    public let metrics: SystemMetrics

    private enum CodingKeys: String, CodingKey {
        case status = "status"
        case uptime = "uptime"
        case lastCheck = "last_check"
        case services = "services"
        case metrics = "metrics"
    }
}

/// System metrics
public struct SystemMetrics: Codable {
    public let cpuUsage: Double
    public let memoryUsage: Double
    public let diskUsage: Double
    public let networkUsage: Double
    public let activeUsers: UInt32
    public let totalRequests: UInt64
    public let errorRate: Double

    private enum CodingKeys: String, CodingKey {
        case cpuUsage = "cpu_usage"
        case memoryUsage = "memory_usage"
        case diskUsage = "disk_usage"
        case networkUsage = "network_usage"
        case activeUsers = "active_users"
        case totalRequests = "total_requests"
        case errorRate = "error_rate"
    }
}

/// Comprehensive demonstration of ALL specta-swift functionality
/// 
/// This example showcases every feature and capability of specta-swift in a single,
/// realistic application scenario. It demonstrates complex type relationships,
/// various enum patterns, special types, and advanced features.
/// Main application types for a task management system
public struct Task: Codable {
    public let id: UInt32
    public let title: String
    public let description: String?
    public let status: TaskStatus
    public let priority: Priority
    public let assignee: User?
    public let createdAt: String
    public let updatedAt: String
    public let dueDate: String?
    public let duration: RustDuration?
    public let tags: [String]
    public let metadata: TaskMetadata
    public let subtasks: [SubTask]

    private enum CodingKeys: String, CodingKey {
        case id = "id"
        case title = "title"
        case description = "description"
        case status = "status"
        case priority = "priority"
        case assignee = "assignee"
        case createdAt = "created_at"
        case updatedAt = "updated_at"
        case dueDate = "due_date"
        case duration = "duration"
        case tags = "tags"
        case metadata = "metadata"
        case subtasks = "subtasks"
    }
}

/// Task metadata
public struct TaskMetadata: Codable {
    public let createdBy: UInt32
    public let lastModifiedBy: UInt32
    public let version: UInt32
    public let customFields: [(String, String)]
    public let attachments: [Attachment]
    public let watchers: [UInt32]
    public let dependencies: [UInt32]

    private enum CodingKeys: String, CodingKey {
        case createdBy = "created_by"
        case lastModifiedBy = "last_modified_by"
        case version = "version"
        case customFields = "custom_fields"
        case attachments = "attachments"
        case watchers = "watchers"
        case dependencies = "dependencies"
    }
}

/// Task status enum with mixed variants
public enum TaskStatus {
    case todo
    case inProgress(TaskStatusInProgressData)
    case blocked(TaskStatusBlockedData)
    case review(TaskStatusReviewData)
    case completed(TaskStatusCompletedData)
    case cancelled(TaskStatusCancelledData)
}
public struct TaskStatusInProgressData: Codable {
    public let startedAt: String
    public let estimatedCompletion: String?
    public let progress: Float

    private enum CodingKeys: String, CodingKey {
        case startedAt = "started_at"
        case estimatedCompletion = "estimated_completion"
        case progress = "progress"
    }
}

public struct TaskStatusBlockedData: Codable {
    public let reason: String
    public let blockedBy: [UInt32]
    public let estimatedUnblock: String?

    private enum CodingKeys: String, CodingKey {
        case reason = "reason"
        case blockedBy = "blocked_by"
        case estimatedUnblock = "estimated_unblock"
    }
}

public struct TaskStatusReviewData: Codable {
    public let reviewer: String
    public let reviewStartedAt: String
    public let comments: [ReviewComment]

    private enum CodingKeys: String, CodingKey {
        case reviewer = "reviewer"
        case reviewStartedAt = "review_started_at"
        case comments = "comments"
    }
}

public struct TaskStatusCompletedData: Codable {
    public let completedAt: String
    public let completionTime: RustDuration
    public let finalNotes: String?

    private enum CodingKeys: String, CodingKey {
        case completedAt = "completed_at"
        case completionTime = "completion_time"
        case finalNotes = "final_notes"
    }
}

public struct TaskStatusCancelledData: Codable {
    public let reason: String
    public let cancelledAt: String

    private enum CodingKeys: String, CodingKey {
        case reason = "reason"
        case cancelledAt = "cancelled_at"
    }
}

// MARK: - TaskStatus Codable Implementation
extension TaskStatus: Codable {
    private enum CodingKeys: String, CodingKey {
        case todo = "Todo"
        case inProgress = "InProgress"
        case blocked = "Blocked"
        case review = "Review"
        case completed = "Completed"
        case cancelled = "Cancelled"
    }

    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        
        if container.allKeys.count != 1 {
            throw DecodingError.dataCorrupted(
                DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Invalid number of keys found, expected one.")
            )
        }

        let key = container.allKeys.first!
        switch key {
        case .todo:
            self = .todo
        case .inProgress:
            let data = try container.decode(TaskStatusInProgressData.self, forKey: .inProgress)
            self = .inProgress(data)
        case .blocked:
            let data = try container.decode(TaskStatusBlockedData.self, forKey: .blocked)
            self = .blocked(data)
        case .review:
            let data = try container.decode(TaskStatusReviewData.self, forKey: .review)
            self = .review(data)
        case .completed:
            let data = try container.decode(TaskStatusCompletedData.self, forKey: .completed)
            self = .completed(data)
        case .cancelled:
            let data = try container.decode(TaskStatusCancelledData.self, forKey: .cancelled)
            self = .cancelled(data)
        }
    }

    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        
        switch self {
        case .todo:
            try container.encodeNil(forKey: .todo)
        case .inProgress(let data):
            try container.encode(data, forKey: .inProgress)
        case .blocked(let data):
            try container.encode(data, forKey: .blocked)
        case .review(let data):
            try container.encode(data, forKey: .review)
        case .completed(let data):
            try container.encode(data, forKey: .completed)
        case .cancelled(let data):
            try container.encode(data, forKey: .cancelled)
        }
    }
}


/// Theme enum (string enum)
public enum Theme: Codable {
    case light
    case dark
    case auto
    case custom
}

/// User information
public struct User: Codable {
    public let id: UInt32
    public let username: String
    public let email: String
    public let profile: UserProfile
    public let preferences: UserPreferences
    public let role: UserRole
    public let isActive: Bool
    public let lastLogin: String?
    public let createdAt: String

    private enum CodingKeys: String, CodingKey {
        case id = "id"
        case username = "username"
        case email = "email"
        case profile = "profile"
        case preferences = "preferences"
        case role = "role"
        case isActive = "is_active"
        case lastLogin = "last_login"
        case createdAt = "created_at"
    }
}

/// User preferences
public struct UserPreferences: Codable {
    public let theme: Theme
    public let notifications: NotificationSettings
    public let privacy: PrivacySettings
    public let display: DisplaySettings
}

/// User profile with nested data
public struct UserProfile: Codable {
    public let firstName: String
    public let lastName: String
    public let bio: String?
    public let avatarUrl: String?
    public let timezone: String
    public let language: String

    private enum CodingKeys: String, CodingKey {
        case firstName = "first_name"
        case lastName = "last_name"
        case bio = "bio"
        case avatarUrl = "avatar_url"
        case timezone = "timezone"
        case language = "language"
    }
}

/// User role with permissions
public enum UserRole {
    case user
    case moderator(UserRoleModeratorData)
    case admin(UserRoleAdminData)
    case superAdmin(UserRoleSuperAdminData)
}
public struct UserRoleModeratorData: Codable {
    public let permissions: [String]
    public let department: String
}

public struct UserRoleAdminData: Codable {
    public let level: AdminLevel
    public let departments: [String]
    public let specialAccess: [String]

    private enum CodingKeys: String, CodingKey {
        case level = "level"
        case departments = "departments"
        case specialAccess = "special_access"
    }
}

public struct UserRoleSuperAdminData: Codable {
    public let systemAccess: Bool
    public let auditLogs: Bool

    private enum CodingKeys: String, CodingKey {
        case systemAccess = "system_access"
        case auditLogs = "audit_logs"
    }
}

// MARK: - UserRole Codable Implementation
extension UserRole: Codable {
    private enum CodingKeys: String, CodingKey {
        case user = "User"
        case moderator = "Moderator"
        case admin = "Admin"
        case superAdmin = "SuperAdmin"
    }

    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        
        if container.allKeys.count != 1 {
            throw DecodingError.dataCorrupted(
                DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Invalid number of keys found, expected one.")
            )
        }

        let key = container.allKeys.first!
        switch key {
        case .user:
            self = .user
        case .moderator:
            let data = try container.decode(UserRoleModeratorData.self, forKey: .moderator)
            self = .moderator(data)
        case .admin:
            let data = try container.decode(UserRoleAdminData.self, forKey: .admin)
            self = .admin(data)
        case .superAdmin:
            let data = try container.decode(UserRoleSuperAdminData.self, forKey: .superAdmin)
            self = .superAdmin(data)
        }
    }

    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        
        switch self {
        case .user:
            try container.encodeNil(forKey: .user)
        case .moderator(let data):
            try container.encode(data, forKey: .moderator)
        case .admin(let data):
            try container.encode(data, forKey: .admin)
        case .superAdmin(let data):
            try container.encode(data, forKey: .superAdmin)
        }
    }
}


/// Visibility enum
public enum Visibility: Codable {
    case public
    case friends
    case private
    case hidden
}