import { UsageEntry, UserPreferences } from '../storage'; export abstract class RecoveryTracker { protected usageData: UsageEntry[]; protected preferences: UserPreferences | null; constructor(usageData: UsageEntry[], preferences: UserPreferences | null) { this.usageData = usageData; this.preferences = preferences; } /** * Calculates the number of minutes elapsed since the last usage. * This is the core logic that subclasses must support, but the implementation * heavily depends on the specific substance's data source (preferences timestamp vs usage logs). */ abstract calculateMinutesFree(precise?: boolean): number; /** * Helper to convert milliseconds to minutes with optional precision. */ protected msToMinutes(ms: number, precise: boolean = false): number { const minutes = Math.max(0, ms / (1000 * 60)); return precise ? minutes : Math.floor(minutes); } /** * Helper to check if a timestamp is valid and recent enough to rely on. */ protected isValidTimestamp(timestamp: string | null | undefined): boolean { return !!timestamp && !isNaN(new Date(timestamp).getTime()); } }