/**
 * Shared types for reports-navigation-hub (wave-13, spec 103).
 */

export const REPORT_TYPE_VALUES = [
  'revenue', 'revenue_trends', 'invoices', 'payments', 'time', 'expenses',
  'profitability', 'revenue_forecast', 'leads', 'proposals',
  'ar_aging', 'bad_debt', 'audit', 'api_usage',
  'vat', 'pnl', 'cashflow', 'advance_tax', 'withholding',
  'bituach_leumi', 'uniform_format',
] as const

export type ReportType = typeof REPORT_TYPE_VALUES[number]

export interface ReportShortcutDTO {
  id: string
  tenantId: string
  userId: string
  name: string
  reportType: ReportType
  params: Record<string, unknown>
  createdAt: string
}

export interface ReportShortcutsResponse {
  items: ReportShortcutDTO[]
}

export interface CreateReportShortcutBody {
  name: string
  reportType: ReportType
  params: Record<string, unknown>
}

export interface ReportsSummaryResponse {
  revenue: { total: string | null; currency: string }
  invoices: { sent: number; overdue: number }
  payments: { received: string | null; pending_count: number }
  time: { hours_logged: number | null }
  expenses: { total: string | null; unbilled_count: number }
  profitability: { margin_pct: number | null }
  leads: { new_count: number; converted_count: number }
  proposals: { sent_count: number; pipeline_value: string | null }
  audit: { event_count: number }
  api_usage: { call_count: number }
}

export const REVENUE_FORECAST_MONTHS = [3, 6, 12, 24] as const
export type RevenueForecastMonths = typeof REVENUE_FORECAST_MONTHS[number]

export interface LeadStageProbabilities {
  NEW: number
  CONTACTED: number
  QUALIFIED: number
  PROPOSAL: number
}

export const DEFAULT_LEAD_STAGE_PROBABILITIES: LeadStageProbabilities = {
  NEW: 5,
  CONTACTED: 15,
  QUALIFIED: 30,
  PROPOSAL: 60,
}

export interface RevenueForecastSummary {
  committed: number
  scheduled: number
  projected: number
  total: number
}

export interface RevenueForecastMonth {
  month: string
  committed: number
  scheduled: number
  projected: number
  total: number
}

export interface RevenueForecastResponse {
  summary: RevenueForecastSummary
  monthly: RevenueForecastMonth[]
}

export type DateRangePreset =
  | 'today'
  | 'this_week'
  | 'this_month'
  | 'last_month'
  | 'this_quarter'
  | 'this_year'
  | 'last_12_months'
  | 'custom'
