export type TodayUpcomingAppointment = {
  id: string;
  patientName: string;
  startAt: string;
  endAt: string;
  purpose: string;
};

export type TodaySummaryActions = {
  upcomingAppointmentsToday?: TodayUpcomingAppointment[];
};

export type TodayChartBucket = {
  code: string;
  label: string;
  count: number;
};

export type TodayStackedDayBucket = {
  code: string;
  label: string;
  completed: number;
  received: number;
};

export type TodayPartnerCasesBucket = {
  code: string;
  label: string;
  completed: number;
  pending: number;
};

export type TodayCompletionGauge = {
  completed: number;
  total: number;
  percent: number;
};

export type TodaySummaryCharts = {
  treatmentMixWeek?: TodayChartBucket[];
  tasksByProsthesis?: TodayChartBucket[];
  appointmentsByProvider?: TodayChartBucket[];
  caseCompletion?: TodayCompletionGauge;
  treatmentPlanCompletion?: TodayCompletionGauge;
  appointmentsWeekAll?: TodayChartBucket[];
  appointmentsWeekMine?: TodayChartBucket[];
  labTaskActivityWeek?: TodayStackedDayBucket[];
  casePartnersMonth?: TodayPartnerCasesBucket[];
  casesDueWeek?: TodayChartBucket[];
  efficiencyReport?: TodayChartBucket[];
};

export type TodayWidgetKey =
  | 'appointmentsToday'
  | 'patientsToday'
  | 'treatmentsToday'
  | 'labCasesPendingSend'
  | 'casesReceivedToday'
  | 'casesInProgress'
  | 'tasksInProgress'
  | 'importantTasks'
  | 'overdueCases'
  | 'unassignedTasks'
  | 'pendingConnections'
  | 'pendingStaffInvites'
  | 'providersWithoutWorkingHours';

export type TodaySubscriptionSnapshot = {
  hasActivePlan: boolean;
  planName: string | null;
  seatsUsed: number;
  seatsLimit: number | null;
  seatsUnlimited: boolean;
  seatsPercent: number;
  periodStartAt: string;
  periodEndAt: string | null;
  periodTotalDays: number;
  periodElapsedDays: number;
  periodPercent: number;
};

export type TodaySummaryWidgets = Partial<
  Record<
    TodayWidgetKey,
    | { count: number; membershipIds?: string[] }
    | { used: number; limit: number | null; unlimited: boolean }
  >
>;

export interface TodaySummaryData {
  generatedAt: string;
  orgType: 'CLINIC' | 'LAB';
  range: { from: string; to: string };
  widgets: TodaySummaryWidgets;
  charts: TodaySummaryCharts;
  actions: TodaySummaryActions;
  subscription?: TodaySubscriptionSnapshot;
}

export interface TodaySummaryResponse {
  success: boolean;
  data: TodaySummaryData;
}
