export interface User {
  id: string;
  username: string;
  created_at: string;
}

export interface Routine {
  id: string;
  user_uuid: string;
  name: string;
  description?: string;
  icon?: string;
  created_at: string;
}

export interface RoutineWithSteps extends Routine {
  steps: RoutineStep[];
}

export interface RoutineStep {
  id: string;
  routine_id: string;
  name: string;
  instructions?: string;
  step_type: StepType;
  duration_minutes?: number;
  media_url?: string;
  position: number;
}

export type StepType = 'generic' | 'timer' | 'checklist' | 'meditation' | 'exercise';

export interface RoutineSchedule {
  id: string;
  routine_id: string;
  days: string[];
  time: string;
  remind: boolean;
}

export interface RoutineSession {
  id: string;
  routine_id: string;
  user_uuid: string;
  status: SessionStatus;
  current_step_index: number;
  created_at: string;
  paused_at?: string;
  completed_at?: string;
  abort_reason?: string;
  actual_duration_minutes?: number;
}

export type SessionStatus = 'active' | 'paused' | 'completed' | 'cancelled' | 'aborted';

export interface RoutineTemplate {
  id: string;
  name: string;
  description?: string;
  icon?: string;
  step_count: number;
}

export interface RoutineTemplateWithSteps extends RoutineTemplate {
  steps: RoutineTemplateStep[];
}

export interface RoutineTemplateStep {
  id: string;
  template_id: string;
  name: string;
  instructions?: string;
  step_type: StepType;
  duration_minutes?: number;
  media_url?: string;
  position: number;
}

export interface RoutineStats {
  routine_id: string;
  routine_name: string;
  period_days: number;
  total_sessions: number;
  completed: number;
  aborted: number;
  completion_rate_percent: number;
  avg_duration_minutes: number;
  total_time_minutes: number;
}

export interface RoutineStreak {
  routine_id: string;
  routine_name: string;
  current_streak: number;
  longest_streak: number;
  last_completed_date?: string;
}

export interface WeeklySummary {
  total_completed: number;
  total_time_minutes: number;
  routines_started: number;
  routines: {
    routine_id: string;
    name: string;
    completed_this_week: number;
  }[];
}

export interface RoutineTag {
  id: string;
  name: string;
  color: string;
}

export type MedicationFrequency = 'daily' | 'twice_daily' | 'specific_days' | 'every_n_days' | 'as_needed';

export interface Medication {
  id: string;
  user_uuid: string;
  name: string;
  dosage: string;
  unit: string;
  frequency: MedicationFrequency;
  times: string[];
  days_of_week?: string[];
  interval_days?: number;
  start_date?: string;
  next_dose_date?: string;
  notes?: string;
  active: boolean;
  quantity_remaining?: number;
  refill_date?: string;
  pharmacy_notes?: string;
}

export interface MedicationLog {
  id: string;
  medication_id: string;
  user_uuid: string;
  action: 'taken' | 'skipped';
  scheduled_time?: string;
  notes?: string;
  created_at: string;
}

export interface TodaysMedication {
  medication: Medication;
  scheduled_times: string[];
  taken_times: string[];
  is_prn?: boolean;
}

export interface MedicationAdherence {
  medication_id: string;
  name: string;
  taken: number;
  skipped: number;
  expected?: number;
  adherence_percent: number | null;
  is_prn?: boolean;
}

export interface SessionNote {
  id: string;
  session_id: string;
  step_index?: number;
  note: string;
  created_at: string;
}

export interface AuthResponse {
  token?: string;
  error?: string;
  success?: boolean;
}

export interface ApiError {
  error: string;
}
