export interface Priority {
  title: string;
  severity: 'attention' | 'flag' | string;
  detail: string;
}

export interface HealthMeta {
  current_priorities?: Priority[];
  tests_never_done?: string[];
}

export interface Biomarker {
  name: string;
  panel: string;
  collected: string; // YYYY-MM-DD
  value: string | number;
  value_num: number | null;
  unit: string | null;
  reference_range: string | null;
  flagged: boolean;
}

export interface BiomarkersResponse {
  biomarkers: Biomarker[];
}

export interface DrawsResponse {
  draws: unknown[];
}

export interface WorkoutSet {
  weight_kg: number | null;
  reps: number | null;
  duration_seconds: number | null;
}

export interface WorkoutExercise {
  title: string;
  sets: WorkoutSet[];
}

export interface Workout {
  title: string;
  start_time: string;
  end_time: string;
  exercises: WorkoutExercise[];
}

export interface WorkoutsResponse {
  workouts: Workout[];
  synced_at: string;
}

export interface EightSleepSession {
  ended_at: string;
  total_seconds: number;
  sleep_seconds: number;
  deep_seconds: number;
  rem_seconds: number;
  light_seconds: number;
  awake_seconds: number;
  avg_hrv: number | null;
  avg_hr: number | null;
}

export interface SleepApiResponse {
  sessions: EightSleepSession[];
}

/* Sleep Cycle export: columnar rows keyed by `fields` */
export interface SleepCycleExport {
  exported_at: string;
  fields: string[];
  sessions: (string | number | null)[][];
}

export interface DexaSummary {
  total_body_fat_pct: number;
  total_lean_mass_kg: number;
  total_fat_mass_kg: number;
  total_mass_kg: number;
  est_vat_area_cm2: number;
  est_vat_risk: string;
  appendicular_lean_mass_to_height2_kg_m2: number;
  appendicular_lean_mass_normal_threshold_kg_m2: number;
  total_body_bmd_g_cm2: number;
  resting_metabolic_rate_kcal_day: number;
}

export interface DexaRegion {
  region: string;
  fat_pct: number | null;
  lean_mass_g: number | null;
  fat_mass_g: number | null;
}

export interface DexaIndex {
  measure: string;
  result: number | string;
  unit?: string | null;
  percentile_yn?: number | null;
}

export interface DexaScan {
  scan_date: string;
  provider: string;
  model?: string;
  summary: DexaSummary;
  body_composition_by_region?: DexaRegion[];
  adipose_indices?: DexaIndex[];
  lean_indices?: DexaIndex[];
}

export interface DexaResponse {
  scans: DexaScan[];
}

export interface MeditationStats {
  totalMinutes: number;
  totalSessions: number;
  currentStreak: number;
}

export interface MeditationSession {
  startedAt: string;
  endedAt: string;
  plannedMin: number;
  actualMin: number;
  completionPct: number;
  completed: boolean;
  rating: number | null;
  note: string | null;
}

export interface MeditationSessionsResponse {
  sessions: MeditationSession[];
}

export interface TraitScale {
  left: string;
  right: string;
}

export interface Trait {
  trait: string;
  category: string;
  result: string;
  position_estimate: number | null;
  scale: TraitScale | null;
}

export interface TraitsResponse {
  source: string;
  trait_count: number;
  traits: Trait[];
}

/* ---- shaped ---- */

export interface Night {
  date: string;
  total: number;
  asleep: number;
  deep: number;
  rem: number;
  light: number;
  awake: number;
  quality: number | null;
  hrv: number | null;
  hr: number | null;
  src: string;
}

export interface Week {
  start: string;
  vol: number;
  count: number;
  sets: number;
}

export interface MarkerGroup {
  name: string;
  latest: Biomarker;
  series: { d: string; v: number }[];
  panel: string;
}
