35 lines
1.3 KiB
Swift
35 lines
1.3 KiB
Swift
import Foundation
|
|
|
|
struct Employment: Identifiable {
|
|
let employeeId: Int
|
|
let businessId: Int
|
|
let businessName: String
|
|
let businessAddress: String
|
|
let businessCity: String
|
|
let employeeStatusId: Int
|
|
let pendingTaskCount: Int
|
|
|
|
var id: Int { employeeId }
|
|
|
|
/// Decode directly from a [String: Any] dictionary (matches Flutter's fromJson)
|
|
init(json: [String: Any]) {
|
|
employeeId = WorkTask.parseInt(json["EmployeeID"]) ?? 0
|
|
businessId = WorkTask.parseInt(json["BusinessID"]) ?? 0
|
|
// Server returns "Name" not "BusinessName"
|
|
businessName = (json["Name"] as? String) ?? (json["BusinessName"] as? String) ?? ""
|
|
businessAddress = (json["Address"] as? String) ?? (json["BusinessAddress"] as? String) ?? ""
|
|
businessCity = (json["City"] as? String) ?? (json["BusinessCity"] as? String) ?? ""
|
|
// Match Flutter: read EmployeeStatusID first (server sends StatusID, which may differ)
|
|
employeeStatusId = WorkTask.parseInt(json["EmployeeStatusID"] ?? json["StatusID"]) ?? 0
|
|
pendingTaskCount = WorkTask.parseInt(json["PendingTaskCount"]) ?? 0
|
|
}
|
|
|
|
var statusName: String {
|
|
switch employeeStatusId {
|
|
case 0: return "Pending"
|
|
case 1: return "Active"
|
|
case 2: return "Inactive"
|
|
default: return "Unknown"
|
|
}
|
|
}
|
|
}
|