/**
 * TypeScript type definitions for WooNooW Customer SPA
 */

export interface Product {
  id: number;
  name: string;
  slug: string;
  type: 'simple' | 'variable' | 'grouped' | 'external';
  status: 'publish' | 'draft' | 'pending';
  featured: boolean;
  description: string;
  short_description: string;
  sku: string;
  price: string;
  regular_price: string;
  sale_price: string;
  on_sale: boolean;
  stock_status: 'instock' | 'outofstock' | 'onbackorder';
  stock_quantity: number | null;
  manage_stock: boolean;
  images: ProductImage[];
  categories: ProductCategory[];
  tags: ProductTag[];
  attributes: ProductAttribute[];
  variations?: number[];
  meta_data?: MetaData[];
}

export interface ProductImage {
  id: number;
  src: string;
  name: string;
  alt: string;
}

export interface ProductCategory {
  id: number;
  name: string;
  slug: string;
}

export interface ProductTag {
  id: number;
  name: string;
  slug: string;
}

export interface ProductAttribute {
  id: number;
  name: string;
  position: number;
  visible: boolean;
  variation: boolean;
  options: string[];
}

export interface ProductVariation {
  id: number;
  product_id: number;
  sku: string;
  price: string;
  regular_price: string;
  sale_price: string;
  on_sale: boolean;
  stock_status: 'instock' | 'outofstock' | 'onbackorder';
  stock_quantity: number | null;
  image: ProductImage;
  attributes: Record<string, string>;
}

export interface MetaData {
  key: string;
  value: any;
}

export interface Order {
  id: number;
  number: string;
  status: string;
  date: string;
  total: string;
  currency: string;
  items_count: number;
  items: OrderItem[];
  billing: Address;
  shipping: Address;
  payment_method: string;
  payment_method_title: string;
  shipping_method: string;
  shipping_method_title: string;
}

export interface OrderItem {
  id: number;
  name: string;
  product_id: number;
  variation_id: number;
  quantity: number;
  price: string;
  total: string;
  image?: string;
}

export interface Address {
  first_name: string;
  last_name: string;
  company?: string;
  address_1: string;
  address_2?: string;
  city: string;
  state: string;
  postcode: string;
  country: string;
  email?: string;
  phone?: string;
}

export interface Customer {
  id: number;
  email: string;
  first_name: string;
  last_name: string;
  username: string;
  billing: Address;
  shipping: Address;
  avatar_url: string;
}

export interface ShippingMethod {
  id: string;
  title: string;
  cost: string;
  description?: string;
}

export interface PaymentMethod {
  id: string;
  title: string;
  description?: string;
  icon?: string;
}

// Global window interface for WordPress data
declare global {
  interface Window {
    woonoowCustomer?: {
      apiUrl: string;
      nonce: string;
      customer?: Customer;
      settings?: Record<string, any>;
    };
  }
}
