// Data types for HiHala Dashboard

export interface MuseumRecord {
  date: string;
  district: string;
  museum_name: string;
  channel: string;
  visits: number;
  tickets: number;
  revenue_gross: number;
  revenue_net: number;
  year: string;
  quarter: string;
}

export interface Metrics {
  revenue: number;
  visitors: number;
  tickets: number;
  avgRevPerVisitor: number;
}

export interface Filters {
  year: string;
  district: string;
  channel: string[];
  museum: string[];
  quarter: string;
}

export interface DateRangeFilters {
  district: string;
  channel: string[];
  museum: string[];
}

export interface CacheStatus {
  available: boolean;
  timestamp: string | null;
  age: number | null;
  rows: number;
  isStale?: boolean;
}

export interface CacheResult {
  data: MuseumRecord[];
  isStale: boolean;
  timestamp: number;
}

export interface FetchResult {
  data: MuseumRecord[];
  fromCache: boolean;
  cacheTimestamp?: number;
}

export type DataErrorType = 'config' | 'network' | 'auth' | 'timeout' | 'unknown';

export class DataError extends Error {
  type: DataErrorType;
  constructor(message: string, type: DataErrorType) {
    super(message);
    this.type = type;
  }
}

export interface GroupedData {
  revenue: number;
  visitors: number;
  tickets: number;
}

export interface UmrahData {
  [year: number]: {
    [quarter: number]: number | null;
  };
}

// NocoDB DailySales row (populated by server-side ETL)
export interface NocoDBDailySale {
  Id: number;
  Date: string;
  District: string;
  MuseumName: string;
  Channel: string;
  TicketType: string;
  ComboMuseums: number;
  ComboWith: string;
  Visits: number;
  Tickets: number;
  GrossRevenue: number;
  NetRevenue: number;
}

// Season (hijri calendar overlay)
export interface Season {
  Id?: number;
  Name: string;
  HijriYear: number;
  StartDate: string;
  EndDate: string;
  Color: string;
}

// Chart data types
export interface ChartDataset {
  label?: string;
  data: number[];
  backgroundColor?: string | string[];
  borderColor?: string;
  borderWidth?: number;
  borderRadius?: number;
  tension?: number;
  fill?: boolean;
  pointRadius?: number;
  pointHoverRadius?: number;
  pointBackgroundColor?: string;
  pointBorderColor?: string;
  pointBorderWidth?: number;
  yAxisID?: string;
  order?: number;
  datalabels?: object;
}

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

// Component props
export interface DashboardProps {
  data: MuseumRecord[];
  seasons: Season[];
  showDataLabels: boolean;
  setShowDataLabels: (value: boolean) => void;
  includeVAT: boolean;
  setIncludeVAT: (value: boolean) => void;
}

export interface ComparisonProps {
  data: MuseumRecord[];
  seasons: Season[];
  showDataLabels: boolean;
  setShowDataLabels: (value: boolean) => void;
  includeVAT: boolean;
  setIncludeVAT: (value: boolean) => void;
}

export interface SlidesProps {
  data: MuseumRecord[];
}

// Quarterly table row
export interface QuarterlyRow {
  q: number;
  rev24: number;
  rev25: number;
  revChg: number;
  vis24: number;
  vis25: number;
  visChg: number;
  cap24: number | null;
  cap25: number | null;
}

// Metric card for comparison
export interface MetricCardData {
  title: string;
  prev: number | null;
  curr: number | null;
  change: number | null;
  isCurrency?: boolean;
  isPercent?: boolean;
  pendingMessage?: string;
}

// Slide types
export interface SlideConfig {
  id: number;
  title: string;
  chartType: string;
  metric: string;
  startDate: string;
  endDate: string;
  channel: string;
  museum: string;
  showComparison: boolean;
}

export interface ChartTypeOption {
  id: string;
  label: string;
  icon: string;
}

export interface MetricOption {
  id: string;
  label: string;
  field: string;
}

export interface MetricFieldInfo {
  field: string;
  label: string;
}

// Translation function type
export type TranslateFunction = (key: string) => string;
