// Clover API Types

export interface CloverConfig {
  apiKey?: string;
  accessToken?: string;
  merchantId: string;
  environment?: 'sandbox' | 'production';
}

export interface CloverOrder {
  id: string;
  currency: string;
  employee?: { id: string };
  total: number;
  title?: string;
  note?: string;
  state: 'open' | 'locked' | 'paid';
  manualTransaction?: boolean;
  groupLineItems?: boolean;
  testMode?: boolean;
  createdTime?: number;
  clientCreatedTime?: number;
  modifiedTime?: number;
  deletedTime?: number;
  lineItems?: CloverLineItem[];
  customers?: CloverCustomer[];
}

export interface CloverLineItem {
  id: string;
  orderRef: { id: string };
  item: { id: string };
  name: string;
  price: number;
  unitQty?: number;
  printed?: boolean;
  exchanged?: boolean;
  refunded?: boolean;
  isRevenue?: boolean;
  modifications?: CloverModification[];
  discounts?: CloverDiscount[];
}

export interface CloverModification {
  id: string;
  name: string;
  amount: number;
  modifier: { id: string };
}

export interface CloverItem {
  id: string;
  hidden?: boolean;
  name: string;
  price: number;
  priceType?: 'FIXED' | 'PER_UNIT' | 'VARIABLE';
  defaultTaxRates?: boolean;
  cost?: number;
  isRevenue?: boolean;
  stockCount?: number;
  sku?: string;
  code?: string;
  modifiedTime?: number;
  categories?: { id: string }[];
  tags?: CloverTag[];
  modifierGroups?: CloverModifierGroup[];
}

export interface CloverCategory {
  id: string;
  name: string;
  sortOrder?: number;
  deleted?: boolean;
  modifiedTime?: number;
  items?: { id: string }[];
}

export interface CloverModifierGroup {
  id: string;
  name: string;
  showByDefault?: boolean;
  modifiers?: CloverModifier[];
}

export interface CloverModifier {
  id: string;
  name: string;
  price: number;
  modifierGroup?: { id: string };
}

export interface CloverTag {
  id: string;
  name: string;
  items?: { id: string }[];
}

export interface CloverCustomer {
  id: string;
  firstName: string;
  lastName: string;
  marketingAllowed?: boolean;
  customerSince?: number;
  orders?: CloverOrder[];
  addresses?: CloverAddress[];
  emailAddresses?: CloverEmailAddress[];
  phoneNumbers?: CloverPhoneNumber[];
  cards?: CloverCard[];
}

export interface CloverAddress {
  id: string;
  address1?: string;
  address2?: string;
  address3?: string;
  city?: string;
  state?: string;
  zip?: string;
  country?: string;
}

export interface CloverEmailAddress {
  id: string;
  emailAddress: string;
  primaryEmail?: boolean;
}

export interface CloverPhoneNumber {
  id: string;
  phoneNumber: string;
}

export interface CloverCard {
  id: string;
  first6: string;
  last4: string;
  cardType: string;
  expirationDate: string;
  token: string;
}

export interface CloverEmployee {
  id: string;
  name: string;
  nickname?: string;
  customId?: string;
  email?: string;
  inviteSent?: boolean;
  claimedTime?: number;
  deletedTime?: number;
  pin?: string;
  role: string;
  shifts?: CloverShift[];
}

export interface CloverShift {
  id: string;
  employee: { id: string };
  cashTipsCollected?: number;
  serverBanking?: boolean;
  inTime?: number;
  outTime?: number;
}

export interface CloverPayment {
  id: string;
  order: { id: string };
  device?: { id: string };
  amount: number;
  tipAmount?: number;
  taxAmount?: number;
  cashbackAmount?: number;
  cashTendered?: number;
  externalPaymentId?: string;
  employee: { id: string };
  createdTime: number;
  clientCreatedTime?: number;
  modifiedTime?: number;
  offline?: boolean;
  result: 'SUCCESS' | 'FAIL' | 'INITIATED' | 'VOIDED' | 'VOIDING' | 'AUTH' | 'AUTH_COMPLETED';
  cardTransaction?: CloverCardTransaction;
  refunds?: CloverRefund[];
}

export interface CloverCardTransaction {
  cardType: string;
  entryType: string;
  first6: string;
  last4: string;
  authCode?: string;
  referenceId?: string;
  transactionNo?: string;
  state: 'PENDING' | 'CLOSED';
  extra?: any;
}

export interface CloverRefund {
  id: string;
  orderRef: { id: string };
  device?: { id: string };
  amount: number;
  taxAmount?: number;
  tipAmount?: number;
  employee: { id: string };
  createdTime: number;
  clientCreatedTime?: number;
  payment: { id: string };
}

export interface CloverMerchant {
  id: string;
  name: string;
  address?: CloverAddress;
  phoneNumber?: string;
  website?: string;
  owner?: { id: string };
  createdTime?: number;
  modifiedTime?: number;
}

export interface CloverDevice {
  id: string;
  serial: string;
  model: string;
  merchant: { id: string };
  pedType?: string;
  terminalPrefix?: string;
  productName?: string;
}

export interface CloverTenderType {
  id: string;
  editable?: boolean;
  labelKey: string;
  label: string;
  opensCashDrawer?: boolean;
  enabled?: boolean;
  visible?: boolean;
}

export interface CloverDiscount {
  id: string;
  name: string;
  amount?: number;
  percentage?: number;
}

export interface CloverTaxRate {
  id: string;
  name: string;
  rate: number;
  isDefault?: boolean;
}

export interface CloverCashEvent {
  id: string;
  device: { id: string };
  employee: { id: string };
  timestamp: number;
  amountChange: number;
  type: 'ADD' | 'REMOVE' | 'OPEN_DRAWER';
  note?: string;
}

export interface PaginatedResponse<T> {
  elements: T[];
  href?: string;
}

export interface SalesSummary {
  totalSales: number;
  totalOrders: number;
  averageOrderValue: number;
  totalRefunds: number;
  netSales: number;
  totalTax: number;
  totalTips: number;
}

export interface RevenueByItem {
  itemId: string;
  itemName: string;
  quantitySold: number;
  totalRevenue: number;
  averagePrice: number;
}

export interface RevenueByCategory {
  categoryId: string;
  categoryName: string;
  itemCount: number;
  totalRevenue: number;
}

export interface EmployeePerformance {
  employeeId: string;
  employeeName: string;
  totalSales: number;
  orderCount: number;
  averageOrderValue: number;
  totalHours?: number;
}
