// types/siteData.ts
export type SiteName = 'Site A' | 'Site B' | 'Site C';

export interface SiteDetails {
    location: string;
    inverterProvider: string;
    emergencyContact: string;
    lastSyncTimestamp: string;
    consumptionData: number[]; // e.g., Daily consumption in kWh
    generationData: number[]; // e.g., Daily generation in kWh

    // Properties for SystemOverview
    systemStatus: string; // e.g., "Normal", "Faulty"
    temperature: string; // e.g., "35°C"
    solarPower: number; // Power generated by solar (kW) - Real-time
    realTimePower: number; // Real-time power used (kW)
    installedPower: number; // Installed capacity (kWp)

    // New properties for KPI calculations (assuming these are base values for the month)
    // If consumptionData/generationData are daily, we will sum them up.
    // If they were monthly totals, you'd name them appropriately.
    // Let's assume these are the *raw data points* for the month.
    // monthlyConsumptionkWh?: number; // Optional, if you want to store a pre-calculated total
    // monthlyGenerationkWh?: number; // Optional, if you want to store a pre-calculated total
    
    // For savings calculation:
    gridImportPrice_RM_per_kWh: number; // Price paid for electricity from the grid
    solarExportTariff_RM_per_kWh: number; // Price received for excess solar sent to grid (e.g., FiT)
    theoreticalMaxGeneration_kWh?: number; // For efficiency calculation (e.g., based on installedPower * peak sun hours)
}

// Helper function to sum data for monthly totals (if consumptionData/generationData are daily)
const calculateMonthlyTotal = (dataArray: number[]): number => {
    return dataArray.reduce((sum, value) => sum + value, 0);
};

const generateYearlyDataInRange = (min: number, max: number) =>
  Array(365)
    .fill(0)
    .map(() => Math.floor(Math.random() * (max - min + 1)) + min);


export const mockSiteData: Record<SiteName, SiteDetails> = {
    'Site A': {
        location: 'Petaling Jaya, Selangor',
        inverterProvider: 'SolarEdge',
        emergencyContact: '+60 12-345 6789',
        lastSyncTimestamp: '2025-06-03 15:30:00',
        consumptionData: generateYearlyDataInRange(80, 250),
        generationData: generateYearlyDataInRange(80, 250),
        systemStatus: 'Normal',
        temperature: '35°C',
        solarPower: 108.4,
        realTimePower: 108.4,
        installedPower: 174.9, // kWp
        gridImportPrice_RM_per_kWh: 0.50, // Example: RM 0.50 per kWh
        solarExportTariff_RM_per_kWh: 0.30, // Example: RM 0.30 per kWh
        theoreticalMaxGeneration_kWh: 80000, // Example: Theoretical max for 174.9 kWp over a month in Malaysia
    },
    'Site B': {
        location: 'Kuala Lumpur, Wilayah Persekutuan',
        inverterProvider: 'Huawei',
        emergencyContact: '+60 19-876 5432',
        lastSyncTimestamp: '2025-06-02 10:15:00',
        consumptionData: generateYearlyDataInRange(200, 450),
        generationData: generateYearlyDataInRange(200, 450),
        systemStatus: 'Normal',
        temperature: '32°C',
        solarPower: 95.2,
        realTimePower: 95.2,
        installedPower: 150.0,
        gridImportPrice_RM_per_kWh: 0.52,
        solarExportTariff_RM_per_kWh: 0.32,
        theoreticalMaxGeneration_kWh: 190000,
    },
    'Site C': {
        location: 'Johor Bahru, Johor',
        inverterProvider: 'Enphase',
        emergencyContact: '+60 13-555 1234',
        lastSyncTimestamp: '2025-06-03 08:00:00',
        consumptionData: generateYearlyDataInRange(400, 550),
        generationData: generateYearlyDataInRange(400, 550),
        systemStatus: 'Faulty',
        temperature: '30°C',
        solarPower: 25.0,
        realTimePower: 70.0,
        installedPower: 120.0,
        gridImportPrice_RM_per_kWh: 0.48,
        solarExportTariff_RM_per_kWh: 0.28,
        theoreticalMaxGeneration_kWh: 180000, // Lower theoretical max due to fault or smaller system
    },
};