export interface PoseSettings {
  model: string
  delegate: 'GPU' | 'CPU'
  numPoses: number
  minDetectionConfidence: number
  minTrackingConfidence: number
  minPresenceConfidence: number
  // Step detection
  stepThresholdX: number
  stepThresholdZ: number
  stepReset: number
  showDebug: boolean
}

export const DEFAULT_SETTINGS: PoseSettings = {
  model: 'pose_landmarker_heavy',
  delegate: 'GPU',
  numPoses: 1,
  minDetectionConfidence: 0.75,
  minTrackingConfidence: 0.5,
  minPresenceConfidence: 0.5,
  stepThresholdX: 0.17,
  stepThresholdZ: 0.12,
  stepReset: 0.09,
  showDebug: false,
}

const STORAGE_KEY = 'poseSettings'

export function loadSettings(): PoseSettings {
  try {
    const raw = localStorage.getItem(STORAGE_KEY)
    if (raw) return { ...DEFAULT_SETTINGS, ...JSON.parse(raw) }
  } catch { /* ignore */ }
  return DEFAULT_SETTINGS
}

export function saveSettings(settings: PoseSettings) {
  try {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(settings))
  } catch { /* ignore */ }
}
