/**
 * Sustainability TypeScript Types
 * Environmental impact, SDG compliance, and grant reporting
 */

export interface PeriodInfo {
  start_date: string;
  end_date: string;
  days: number;
}

export interface WasteMetrics {
  total_waste_kg: number;
  production_waste_kg: number;
  expired_waste_kg: number;
  waste_percentage: number;
  waste_by_reason: Record<string, number>;
}

export interface CO2Emissions {
  kg: number;
  tons: number;
  trees_to_offset: number;
}

export interface WaterFootprint {
  liters: number;
  cubic_meters: number;
}

export interface LandUse {
  square_meters: number;
  hectares: number;
}

export interface HumanEquivalents {
  car_km_equivalent: number;
  smartphone_charges: number;
  showers_equivalent: number;
  trees_planted: number;
}

export interface EnvironmentalImpact {
  co2_emissions: CO2Emissions;
  water_footprint: WaterFootprint;
  land_use: LandUse;
  human_equivalents: HumanEquivalents;
}

export interface SDG123Metrics {
  baseline_waste_percentage: number;
  current_waste_percentage: number;
  reduction_achieved: number;
  target_reduction: number;
  progress_to_target: number;
  status: 'sdg_compliant' | 'on_track' | 'progressing' | 'baseline' | 'above_baseline';
  status_label: string;
  target_waste_percentage: number;
}

export interface SDGCompliance {
  sdg_12_3: SDG123Metrics;
  baseline_period: string;
  certification_ready: boolean;
  improvement_areas: string[];
}

export interface EnvironmentalImpactAvoided {
  co2_kg: number;
  water_liters: number;
}

export interface AvoidedWaste {
  waste_avoided_kg: number;
  ai_assisted_batches: number;
  environmental_impact_avoided: EnvironmentalImpactAvoided;
  methodology: string;
}

export interface FinancialImpact {
  waste_cost_eur: number;
  cost_per_kg: number;
  potential_monthly_savings: number;
  annual_projection: number;
}

export interface GrantProgramEligibility {
  eligible: boolean;
  confidence: 'high' | 'medium' | 'low';
  requirements_met: boolean;
  funding_eur?: number;
  deadline?: string;
  program_type?: string;
  sector_specific?: string;
}

export interface SpainCompliance {
  law_1_2025: boolean;
  circular_economy_strategy: boolean;
}

export interface GrantReadiness {
  overall_readiness_percentage: number;
  grant_programs: Record<string, GrantProgramEligibility>;
  recommended_applications: string[];
  spain_compliance?: SpainCompliance;
}

export interface SustainabilityMetrics {
  period: PeriodInfo;
  waste_metrics: WasteMetrics;
  environmental_impact: EnvironmentalImpact;
  sdg_compliance: SDGCompliance;
  avoided_waste: AvoidedWaste;
  financial_impact: FinancialImpact;
  grant_readiness: GrantReadiness;
  // Data sufficiency flags
  data_sufficient: boolean;
  minimum_production_required_kg?: number;
  current_production_kg?: number;
}

export interface SustainabilityWidgetData {
  total_waste_kg: number;
  waste_reduction_percentage: number;
  co2_saved_kg: number;
  water_saved_liters: number;
  trees_equivalent: number;
  sdg_status: string;
  sdg_progress: number;
  grant_programs_ready: number;
  financial_savings_eur: number;
}

// Grant Report Types

export interface BaselineComparison {
  baseline: number;
  current: number;
  improvement: number;
}

export interface SupportingData {
  baseline_comparison: BaselineComparison;
  environmental_benefits: EnvironmentalImpact;
  financial_benefits: FinancialImpact;
}

export interface Certifications {
  sdg_12_3_compliant: boolean;
  grant_programs_eligible: string[];
}

export interface ExecutiveSummary {
  total_waste_reduced_kg: number;
  waste_reduction_percentage: number;
  co2_emissions_avoided_kg: number;
  financial_savings_eur: number;
  sdg_compliance_status: string;
}

export interface ReportMetadata {
  generated_at: string;
  report_type: string;
  period: PeriodInfo;
  tenant_id: string;
}

export interface GrantReport {
  report_metadata: ReportMetadata;
  executive_summary: ExecutiveSummary;
  detailed_metrics: SustainabilityMetrics;
  certifications: Certifications;
  supporting_data: SupportingData;
}
