// Models/LocalIssue.swift // ----------------------- // SwiftData model for issues flagged during an offline inspection. import Foundation import SwiftData @Model final class LocalIssue { @Attribute(.unique) var localId: String var serverId: Int? var inspectionLocalId: String // references LocalInspection.localId var facilityServerId: Int // facility this issue belongs to (replaces areaServerId) var severity: String // "low" | "medium" | "high" | "critical" var issueDescription: String var photoLocalPath: String? // local file path before upload var photoServerPath: String? // server path after upload var createdAt: Date var syncStatus: String // "pending" | "synced" | "failed" var syncRetryCount: Int var syncErrorMessage: String? var inspection: LocalInspection? init( inspectionLocalId: String, facilityServerId: Int, severity: String, description: String ) { self.localId = UUID().uuidString self.serverId = nil self.inspectionLocalId = inspectionLocalId self.facilityServerId = facilityServerId self.severity = severity self.issueDescription = description self.photoLocalPath = nil self.photoServerPath = nil self.createdAt = Date() self.syncStatus = "pending" self.syncRetryCount = 0 self.syncErrorMessage = nil } var severityColor: String { switch severity { case "critical": return "red" case "high": return "orange" case "medium": return "yellow" default: return "blue" } } }