//
//  AppModel.swift
//  HelloVisionOS - Niall George Horn - June 2026
//

import SwiftUI
import Observation
import os.log

private let appLogger = Logger(subsystem: "RottenOS.HelloVisionOS", category: "AppModel")

@MainActor
@Observable
class AppModel {

    /// Shared CoreIK bridge — loaded eagerly at init
    let bridge: CoreIKBridge

    init() {
        let b = CoreIKBridge()
        b.load()
        bridge = b
        solverStatus = b.isLoaded
            ? "Solver: active | Joints: \(b.jointCount)"
            : b.statusMessage
        totalJoints = max(b.jointCount, 91)
        appLogger.info("AppModel.init — bridge: \(b.statusMessage)")
    }

    // Wrist end-effector positions (head locked, no sliders for it)

    var headX: Float =  0.00
    var headY: Float =  1.73
    var headZ: Float =  0.00

    var leftX: Float = -0.30
    var leftY: Float =  0.90
    var leftZ: Float = -0.20

    var rightX: Float =  0.30
    var rightY: Float =  0.90
    var rightZ: Float = -0.20

    // Burst solve — set when a slider value changes, causes one high-iter frame
    var needsBurst = false

    // Solver Status

    var solverStatus: String
    var nonZeroJoints = 0
    var totalJoints: Int
}
