export interface ApiResponse<T> {
  success: boolean;
  data?: T;
  error?: { code: string; message: string; field?: string };
}

export interface AuthTokenResponse {
  accessToken: string;
  refreshToken: string;
  expiresAt: string;
  userId: string;
  cafeId: string;
  role: string;
  planTier: string;
  language: string;
  actor?: string;
  branchId?: string | null;
}

export interface MenuCategory {
  id: string;
  name: string;
  nameAr?: string;
  nameEn?: string;
  sortOrder: number;
  taxId?: string;
  discountPercent: number;
  icon?: string;
  iconPresetId?: string;
  iconStyle?: string;
  imageUrl?: string;
  isActive: boolean;
}

export interface MenuItem {
  id: string;
  categoryId: string;
  name: string;
  nameAr?: string;
  nameEn?: string;
  description?: string;
  price: number;
  imageUrl?: string;
  videoUrl?: string;
  model3dUrl?: string;
  isAvailable: boolean;
}

export interface OrderItemLine {
  id: string;
  menuItemId: string;
  menuItemName: string;
  quantity: number;
  unitPrice: number;
  notes?: string;
  isVoided?: boolean;
  voidedAt?: string | null;
}

export interface PaymentLine {
  id: string;
  method: string;
  amount: number;
  status: string;
  reference?: string;
}

export interface Order {
  id: string;
  cafeId: string;
  branchId?: string;
  tableId?: string;
  tableNumber?: string;
  guestName?: string;
  guestPhone?: string;
  customerName?: string;
  customerPhone?: string;
  customerId?: string;
  employeeId?: string;
  orderType: string;
  status: string;
  subtotal: number;
  taxTotal: number;
  discountAmount: number;
  total: number;
  paidAmount: number;
  createdAt: string;
  items: OrderItemLine[];
  payments: PaymentLine[];
}

export type TableBoardStatus = "Free" | "Busy" | "Reserved" | "Cleaning";

export interface TableBoardItem {
  id: string;
  branchId: string;
  sectionId?: string | null;
  sectionName?: string | null;
  sortOrder?: number;
  number: string;
  capacity: number;
  floor?: string;
  qrCode: string;
  qrCodeUrl: string;
  imageUrl?: string;
  videoUrl?: string;
  isActive: boolean;
  isCleaning: boolean;
  status: TableBoardStatus;
  currentOrder?: {
    orderId: string;
    status: string;
    total: number;
    guestLabel?: string;
    source?: string;
  };
}

export interface LiveOrder {
  id: string;
  status: string;
  tableNumber?: number;
  orderType: string;
  total: number;
  createdAt: string;
  items: OrderItemLine[];
}

export type CustomerGroup = "Regular" | "Vip" | "New" | "Employee";
export type CouponType = "Percentage" | "FixedAmount" | "FreeItem";

export interface Customer {
  id: string;
  name: string;
  phone: string;
  nationalId?: string;
  birthDateJalali?: string;
  group: CustomerGroup;
  loyaltyPoints: number;
  referredBy?: string;
  createdAt: string;
}

export interface Coupon {
  id: string;
  code: string;
  type: CouponType;
  value: number;
  minOrderAmount?: number;
  maxDiscount?: number;
  usageLimit?: number;
  usedCount: number;
  targetGroup?: CustomerGroup;
  startsAt?: string;
  expiresAt?: string;
  isActive: boolean;
}

export interface SmsUsage {
  usedThisMonth: number;
  monthlyLimit: number;
  month: string;
}

export interface SmsCampaignResult {
  sentCount: number;
  failedCount: number;
}

export interface Table {
  id: string;
  branchId?: string;
  number: string;
  capacity: number;
  floor?: string;
  qrCode: string;
  qrUrl: string;
  isActive: boolean;
}

export type QueueTicketStatus = "Waiting" | "Called" | "Done" | "Cancelled";

export interface QueueTicket {
  id: string;
  branchId?: string;
  serviceDate: string;
  number: number;
  customerLabel?: string;
  orderId?: string;
  status: QueueTicketStatus;
  issuedAt: string;
}

export interface QueueBoard {
  serviceDate: string;
  nowServing?: number | null;
  lastIssued: number;
  waitingCount: number;
  tickets: QueueTicket[];
}
