/**
 * Stats API TypeScript Interfaces
 *
 * Types for the daily/weekly/monthly gallons delivery charts
 * and totals comparison statistics.
 */

// ============================================
// Daily Gallons Endpoint Types
// ============================================

export interface DailyGallonsDataPoint {
  date: string;  // YYYY-MM-DD format
  gallons: number;
  deliveries: number;
}

export interface DailyGallonsYearData {
  year: number;
  data: DailyGallonsDataPoint[];
}

export interface DailyGallonsResponse {
  ok: boolean;
  years: DailyGallonsYearData[];
}

// ============================================
// Weekly Gallons Endpoint Types
// ============================================

export interface WeeklyGallonsDataPoint {
  week_start: string;  // YYYY-MM-DD (Monday)
  week_end: string;    // YYYY-MM-DD (Sunday)
  week_number: number;
  gallons: number;
  deliveries: number;
}

export interface WeeklyGallonsYearData {
  year: number;
  data: WeeklyGallonsDataPoint[];
}

export interface WeeklyGallonsResponse {
  ok: boolean;
  years: WeeklyGallonsYearData[];
}

// ============================================
// Weekly Customer Signups Endpoint Types
// ============================================

export interface WeeklyCustomerDataPoint {
  week_number: number;
  week_start: string;  // YYYY-MM-DD
  signups: number;
}

export interface WeeklyCustomerYearData {
  year: number;
  data: WeeklyCustomerDataPoint[];
}

export interface WeeklyCustomerResponse {
  ok: boolean;
  years: WeeklyCustomerYearData[];
}

// ============================================
// Monthly Gallons Endpoint Types
// ============================================

export interface MonthlyGallonsDataPoint {
  month: number;       // 1-12
  month_name: string;  // "January", "February", etc.
  gallons: number;
  deliveries: number;
}

export interface MonthlyGallonsYearData {
  year: number;
  data: MonthlyGallonsDataPoint[];
}

export interface MonthlyGallonsResponse {
  ok: boolean;
  years: MonthlyGallonsYearData[];
}

// ============================================
// Totals Comparison Endpoint Types
// ============================================

export interface PeriodComparison {
  current: number;
  previous: number;
  change_percent: number;  // Positive = increase, negative = decrease
  change_direction: 'up' | 'down' | 'neutral';
}

export interface TotalsComparisonData {
  today: {
    gallons: PeriodComparison;
    deliveries: PeriodComparison;
    revenue: PeriodComparison;
  };
  week_to_date: {
    gallons: PeriodComparison;
    deliveries: PeriodComparison;
    revenue: PeriodComparison;
  };
  month_to_date: {
    gallons: PeriodComparison;
    deliveries: PeriodComparison;
    revenue: PeriodComparison;
  };
  year_to_date: {
    gallons: PeriodComparison;
    deliveries: PeriodComparison;
    revenue: PeriodComparison;
  };
}

export interface TotalsComparisonResponse {
  ok: boolean;
  comparison: TotalsComparisonData;
  current_year: number;
  compare_year: number;
}

// ============================================
// Request Parameter Types
// ============================================

export interface DailyGallonsParams {
  start_date: string;  // YYYY-MM-DD
  end_date: string;    // YYYY-MM-DD
  years: number[];     // e.g., [2024, 2025, 2026]
}

export interface WeeklyGallonsParams {
  start_date: string;  // YYYY-MM-DD
  end_date: string;    // YYYY-MM-DD
  years: number[];
}

export interface MonthlyGallonsParams {
  year: number;
  compare_years: number[];
}

// ============================================
// Chart Data Types (transformed for Chart.js)
// ============================================

export interface ChartDataset {
  label: string;
  data: number[];
  borderColor: string;
  backgroundColor: string;
  tension: number;
  fill: boolean;
}

export interface ChartData {
  labels: string[];
  datasets: ChartDataset[];
}

// ============================================
// Time Range Selection
// ============================================

export type TimeRange = 'day' | 'week' | 'month';

export interface DateRange {
  start: Date;
  end: Date;
}
