2222// Platforms: iOS 17+, watchOS 10+
2323
2424import SwiftUI
25+ #if canImport(UIKit)
26+ import UIKit
27+ #endif
2528
2629// MARK: - Buddy Mood
2730
@@ -42,15 +45,38 @@ enum BuddyMood: String, Equatable, Sendable {
4245
4346 static func from(
4447 assessment: HeartAssessment ,
48+ readinessScore: Int ? = nil ,
4549 nudgeCompleted: Bool = false ,
4650 feedbackType: DailyFeedback ? = nil ,
4751 activityInProgress: Bool = false
4852 ) -> BuddyMood {
4953 if nudgeCompleted { return . conquering }
5054 if feedbackType == . positive { return . conquering }
5155 if activityInProgress { return . active }
56+
57+ // Use readiness score as primary signal (coherent with Thump Check card).
58+ // Only show .tired when BOTH anomaly status AND readiness agree the user
59+ // should rest — prevents "Rest Up" contradicting "Good to go" (BUG-1).
60+ if let score = readinessScore {
61+ if score >= 80 { return . thriving }
62+ if score >= 60 {
63+ // Moderate-to-good readiness: show content unless stress is high
64+ return assessment. stressFlag ? . stressed : . content
65+ }
66+ if score >= 40 {
67+ // Below average: nudging toward recovery
68+ return assessment. stressFlag ? . stressed : . nudging
69+ }
70+ // Low readiness (< 40): genuinely tired — BUT only show sleeping
71+ // mood in evening hours. During daytime, show nudging instead.
72+ let hour = Calendar . current. component ( . hour, from: Date ( ) )
73+ let isEvening = hour >= 20 || hour < 6
74+ return isEvening ? . tired : . nudging
75+ }
76+
77+ // Fallback for nil readiness (first run, no data)
5278 if assessment. stressFlag { return . stressed }
53- if assessment. status == . needsAttention { return . tired }
79+ if assessment. status == . needsAttention { return . nudging }
5480 if assessment. status == . improving {
5581 if let cardio = assessment. cardioScore, cardio >= 70 { return . thriving }
5682 return . content
@@ -300,7 +326,7 @@ struct ThumpBuddy: View {
300326 // Haptic
301327 #if os(watchOS)
302328 WKInterfaceDevice . current ( ) . play ( . click)
303- #else
329+ #elseif canImport(UIKit)
304330 UIImpactFeedbackGenerator ( style: . medium) . impactOccurred ( )
305331 #endif
306332
@@ -345,7 +371,7 @@ struct ThumpBuddy: View {
345371 // Haptic — soft
346372 #if os(watchOS)
347373 WKInterfaceDevice . current ( ) . play ( . success)
348- #else
374+ #elseif canImport(UIKit)
349375 UIImpactFeedbackGenerator ( style: . soft) . impactOccurred ( )
350376 #endif
351377
0 commit comments