/**
 * Shape of the live command-center payload produced by the Convex query
 * `api.dashboard.commandCenter`. Types only — the data itself streams from
 * Convex, so this file is safe to import from client components.
 */
export type CCRange = "today" | "7d" | "30d" | "month" | "lastMonth" | "quarter" | "year" | "lastYear" | "custom";

export interface CCReservation {
  id: string;
  code: string;
  status: string;
  source: string;
  checkIn: string;
  checkOut: string;
  actualCheckOut: string | null;
  nights: number;
  guests: number;
  totalAmount: number;
  amountPaid: number;
  balance: number;
  apartment: { id: string; code: string; name: string; coverImageId: string | null };
  customer: { id: string; fullName: string; phone: string };
  contract: string | null;
  createdBy: string;
  cancelReason: string | null;
  cancelledAt: string | null;
  earlyCheckout: boolean;
  releasedNights: number;
  recoveredNights: number;
}

export interface CCRelease {
  id: string;
  apartment: string;
  start: string;
  end: string;
  nights: number;
  value: number;
  reason: string | null;
  reservation: string | null;
  guest: string | null;
  at: string;
  rebooked: boolean;
}

export interface CCForecast {
  occupied: number;
  reserved: number;
  blocked: number;
  available: number;
  total: number;
  occupancy: number;
}

export interface CommandCenterData {
  generatedAt: string;
  period: { range: string; label: string; start: string; end: string; days: number; today: string };
  hero: { gross: number; grossDelta: number | null; net: number; expenses: number; expensesDelta: number | null; profit: number; profitDelta: number | null; margin: number; realized: number; expected: number; outstanding: number; deposits: number; paid: number; pending: number; commissions: number; avgBooking: number; adr: number; revpaa: number; occupancy: number; occupancyDelta: number | null; nights: number; reservations: number; reservationsDelta: number | null; cancelled: number };
  trend: { label: string; key: string; revenue: number; previous: number; expenses: number; profit: number; reservations: number; occupancy: number; checkIns: number; checkOuts: number }[];
  ops: { inHouse: CCReservation[]; arriving: CCReservation[]; departing: CCReservation[]; upcoming: CCReservation[]; cancelled: CCReservation[]; released: CCRelease[] };
  portfolio: { id: string; code: string; name: string; coverImageId: string | null; status: string; cleaningStatus: string; maintenanceStatus: string; basePrice: number; maxGuests: number; building: string | null; current: { id: string; guest: string; checkOut: string } | null; next: { id: string; guest: string; checkIn: string; source: string } | null; occupancy30: number; block: { type: string; source: string; guest: string | null } | null; openMaintenance: number }[];
  statusCounts: Record<string, number>;
  forecast: { today: CCForecast; tomorrow: CCForecast; d7: CCForecast; d14: CCForecast; d30: CCForecast };
  heatmap: { days: { key: string; label: string }[]; rows: { id: string; code: string; cells: ("occupied" | "reserved" | "blocked" | "available")[] }[] };
  workers: { id: string; name: string; role: string; roleKey: string; online: boolean; lastSeenAt: string | null; lastLoginAt: string | null; created30: number; confirmed30: number; cancelled30: number; today: number; d7: number; checkIns: number; checkOuts: number; revenue30: number; commissionPending: number; commissionPaid: number; spark: number[]; score: number; recent: { id: string; action: string; label: string | null; at: string }[] }[];
  activity: { id: string; action: string; userName: string; roleKey: string; entityType: string | null; entityId: string | null; entityLabel: string | null; previousValue: string | null; newValue: string | null; reason: string | null; createdAt: string; reservationId: string | null; apartmentId: string | null; customerId: string | null }[];
  attention: { id: string; severity: "critical" | "important" | "normal"; title: string; detail: string; href: string; count: number }[];
  opportunities: { id: string; title: string; detail: string; value?: number; href: string; tone: "positive" | "warning" | "info" }[];
  insights: string[];
  recovery: { releasedNights: number; recoveredNights: number; recoveredRevenue: number; lostRevenue: number; reopened30: { nights: number; value: number }; rebookRate: number };
  bySource: { name: string; color: string; value: number; revenue: number }[];
  expensesByCategory: { name: string; value: number }[];
}
