import api from './api';

export interface AnalyticsOverview {
    totalBatches: number;
    activeBatches: number;
    totalRooms: number;
    tasksCompletedThisWeek: number;
    tasksPending: number;
    touchPointsToday: number;
    totalPlants: number;
}

export interface BatchYield {
    batchId: string;
    batchName: string;
    strain: string;
    plantCount: number;
    totalGrams: number;
    logCount: number;
    gramsPerPlant: number;
}

export interface StrainYield {
    strain: string;
    totalGrams: number;
    totalPlants: number;
    batchCount: number;
    avgGramsPerPlant: number;
}

export interface YieldAnalytics {
    byBatch: BatchYield[];
    byStrain: StrainYield[];
}

export interface TaskSummary {
    completed: number;
    pending: number;
    inProgress: number;
    overdue: number;
    total: number;
}

export interface UserTaskCompletion {
    userId: string;
    userName: string;
    completedCount: number;
}

export interface TaskAnalytics {
    summary: TaskSummary;
    completedByUserThisWeek: UserTaskCompletion[];
}

export const analyticsApi = {
    getOverview: async () => {
        const response = await api.get<AnalyticsOverview>('/analytics/overview');
        return response.data;
    },

    getYield: async () => {
        const response = await api.get<YieldAnalytics>('/analytics/yield');
        return response.data;
    },

    getTasks: async () => {
        const response = await api.get<TaskAnalytics>('/analytics/tasks');
        return response.data;
    }
};
