// analytics/Analytics.ts
import type { Service } from '../types';

export interface AnalyticsEvent {
    name: string;
    ts: number;
    data?: Record<string, any>;
}

export interface IAnalytics extends Service {
    track(name: string, data?: Record<string, any>): void;
    flush(): void;
}

export abstract class BaseAnalytics implements IAnalytics {
    public abstract name: string;
    public readonly serviceType = 'analytics';
    protected startTime = performance.now();

    abstract track(name: string, data?: Record<string, any>): void;
    abstract flush(): void;

    public dispose(): void {
        this.flush();
    }

    protected getTimestamp(): number {
        return Math.floor(performance.now() - this.startTime);
    }
}
