48 lines
1.7 KiB
Swift
48 lines
1.7 KiB
Swift
// Models/LocalScheduledInspection.swift
|
|
// --------------------------------------
|
|
// SwiftData model for planned/recurring inspection assignments (phase36).
|
|
//
|
|
// Read-only reference data pulled from the server (GET /api/v1/scheduled-inspections)
|
|
// and refreshed by SyncManager.pullScheduledInspections() — never created or
|
|
// mutated on device. Surfaced in the "Scheduled" section on the Dashboard and
|
|
// My Inspections. Tapping "Start" opens the normal new-inspection flow with the
|
|
// facility + template preselected; the schedule lifecycle (fulfil / roll-forward)
|
|
// stays server-driven.
|
|
//
|
|
// All non-optional stored properties carry explicit inline defaults so SwiftData
|
|
// lightweight migration can add the new table without a migration plan.
|
|
|
|
import Foundation
|
|
import SwiftData
|
|
|
|
@Model
|
|
final class LocalScheduledInspection {
|
|
|
|
/// Server ID of the ScheduledInspection row — stable unique identity.
|
|
@Attribute(.unique) var serverId: Int = 0
|
|
|
|
var facilityServerId: Int = 0
|
|
var facilityName: String = ""
|
|
var templateServerId: Int = 0
|
|
var templateName: String = ""
|
|
var inspectorId: Int? = nil
|
|
|
|
var frequency: String = "once" // once | daily | weekly | monthly
|
|
var frequencyLabel: String = "" // human-readable label from server
|
|
|
|
/// Raw ISO date string "YYYY-MM-DD" from the server (display fallback).
|
|
var dueDateString: String = ""
|
|
/// Parsed due date — used for @Query sorting. Nil if the string was absent.
|
|
var nextDue: Date? = nil
|
|
|
|
var isOverdue: Bool = false
|
|
var notes: String? = nil
|
|
|
|
/// Last time this row was refreshed from the server pull.
|
|
var updatedAt: Date = Date()
|
|
|
|
init(serverId: Int) {
|
|
self.serverId = serverId
|
|
}
|
|
}
|