import { IProduct } from '../simpleProduct/product.interface'

export type ORDER_TYPE = 'dine_in' | 'takeaway' | 'delivery'

export type ORDER_STATUS = 'pending' | 'confirmed' | 'preparing' | 'ready' | 'delivered' | 'completed' | 'cancelled'

export type PAYMENT_STATUS = 'pending' | 'paid' | 'failed' | 'refunded'

export interface IOrderItemVariation {
  id?: string
  name_en?: string
  name_ar?: string
  price_modifier?: number | string
}

export interface IOrderItem {
  id: string
  order_id: string
  product_id?: string
  product_name_en: string
  product_name_ar: string
  sku?: string | null
  image?: string | null
  quantity: number
  unit_price: string | number
  total_price: string | number
  selected_variations?: (string | IOrderItemVariation)[]
  special_instructions?: string | null
  created_at: string
  updated_at: string
  deleted_at: string
  product: IProduct
}

export interface IOrderItemInput {
  product_id: string
  quantity: number
  selected_variations?: string[]
  special_instructions?: string | null
}

export interface IOrderTableInfo {
  id: string
  table_number: string
  location?: string | null
}

export interface IOrderCustomerAddress {
  id?: string
  address_line?: string
  area?: string
  city?: string
  notes?: string | null
  latitude?: number | null
  longitude?: number | null
  [key: string]: any
}

export interface IOrderTimelineEntry {
  id?: string
  status: ORDER_STATUS
  label_en?: string
  label_ar?: string
  note?: string | null
  performed_by?: string | null
  created_at: string
}

export interface IOrderPaymentEvent {
  id?: string
  payment_status: PAYMENT_STATUS
  payment_method?: string | null
  paid_amount?: number | string | null
  reference?: string | null
  notes?: string | null
  created_at: string
}

export interface IOrderCustomerSummary {
  phone: string
  name: string
  email?: string | null
}

export interface IOrderAmounts {
  subtotal: number | string
  tax_amount: number | string
  delivery_fee: number | string
  service_fee?: number | string
  discount_amount?: number | string
  total_amount: number | string
  total_in_base_currency?: number | string
  currency_code?: string
  currency_symbol?: string
  currency_rate?: number
}

export interface IOrder extends IOrderAmounts {
  id: string
  order_number: string
  user_id: string
  order_type: ORDER_TYPE
  status: ORDER_STATUS
  payment_status: PAYMENT_STATUS
  payment_method?: string
  customer_name: string
  customer_phone: string
  customer_email?: string | null
  table_id?: string | null
  delivery_address_id?: string | null
  pickup_time?: string | null
  estimated_delivery_time?: string | null
  delivery_notes?: string | null
  notes?: string | null
  coupon_code?: string | null
  promotion_code?: string | null
  cancellation_reason?: string | null
  awaiting_payment?: boolean
  created_at: string
  updated_at?: string
  status_label_ar?: string
  status_label_en?: string
  type_label_ar?: string
  type_label_en?: string
  payment_label_en?: string
  payment_label_ar?: string
  user?: {
    id: string
    name: string
    email: string
  } | null
  table?: IOrderTableInfo | null
  delivery_address?: IOrderCustomerAddress | string | null
  customer?: IOrderCustomerSummary | null
  items: IOrderItem[]
  status_history?: IOrderTimelineEntry[]
  payment_history?: IOrderPaymentEvent[]
  metadata?: Record<string, any>
}

export interface IOrderStatisticsPeriod {
  total_orders: number
  revenue: number | string
  pending_orders?: number
}

export interface IOrderStatisticsByType {
  dine_in: number
  takeaway: number
  delivery: number
}

export interface IOrderStatisticsByStatus {
  pending: number
  confirmed: number
  preparing: number
  ready: number
  delivered: number
  completed: number
  cancelled: number
}

export interface IOrderStatistics {
  today: IOrderStatisticsPeriod
  this_month: IOrderStatisticsPeriod
  by_type: IOrderStatisticsByType
  by_status: IOrderStatisticsByStatus
}

export interface IOrderPaymentMethod {
  id: string
  name: string
  code?: string
  type?: string
  is_active?: boolean
  description?: string | null
}

export interface ICurrencyOption {
  id: string
  code: string
  symbol: string
  exchange_rate: number
  is_base: boolean
}

export interface IActiveTable {
  id: string
  table_number: string
  capacity?: number
  location?: string | null
  is_available?: boolean
}

export interface ITransactionSummary {
  id: string
  order_id: string
  payment_method?: string
  status: string
  amount?: number | string
  currency_code?: string
  created_at: string
  updated_at?: string
  verification_notes?: string | null
}
