LegacyWatchCompatibility.swift 1.23 KB
import Foundation
import SwiftUI

enum HRVStatus: String, Codable {
    case fullOfEnergy = "活力满满"
    case normal = "状态正常"
    case overpressure = "压力过载"
}

struct HRVData: Codable {
    var value: Double?
    var hrvBaseline: Double?
    var date: Date?

    var status: HRVStatus? {
        guard let value else { return nil }
        guard let hrvBaseline, hrvBaseline > 0 else { return .normal }
        let ratio = value / hrvBaseline
        if ratio >= 1.05 { return .fullOfEnergy }
        if ratio < 0.9 { return .overpressure }
        return .normal
    }
}

struct UserInfo: Codable {
    var id: Int?
    var pairId: Int?

    var isPaired: Bool {
        pairId != nil
    }
}

extension WatchThemeModel {
    var isDefaultTheme: Bool? {
        isOfficial.map { $0 == 1 }
    }

    func hrvStatusThumnailImageURL(hrvStatus: HRVStatus) -> String? {
        switch hrvStatus {
        case .fullOfEnergy:
            return energeticImageURL
        case .normal:
            return normalImageURL
        case .overpressure:
            return stressfulImageURL
        }
    }
}

extension Text {
    func wenyiheiFont(size: CGFloat) -> Text {
        font(.custom("WenYue-XinQingNianTi-NC-W8", size: size))
    }
}