// ─── Sales Return Item ──────────────────────────────────────────

export interface SalesReturnItem {
  id: number;
  sales_return_id: number;
  invoice_item_id: number | null;
  product_id: number;
  product_name: string;
  product_code: string;
  product_variant_id: number | null;
  variant_name: string | null;
  unit_id: number;
  unit_name: string;
  unit_symbol: string;
  warehouse_id: number | null;
  warehouse_name: string | null;
  description: string | null;
  description_ar: string | null;
  quantity: string;
  unit_price: string;
  discount_percent: string;
  discount_amount: string;
  tax_rate_id: number | null;
  tax_rate_name: string | null;
  tax_rate_percent: string;
  tax_amount: string;
  line_total: string;
  unit_cost: string;
  total_cost: string;
  notes: string | null;
  sort_order: number;
}

export interface SalesReturnItemPayload {
  invoice_item_id?: number | null;
  product_id: number;
  product_variant_id?: number | null;
  unit_id: number;
  warehouse_id?: number | null;
  description?: string | null;
  description_ar?: string | null;
  quantity: number;
  unit_price: number;
  discount_percent?: number;
  discount_amount?: number;
  tax_rate_id?: number | null;
  notes?: string | null;
  sort_order?: number;
}

// ─── Sales Return ───────────────────────────────────────────────

export interface SalesReturn {
  id: number;
  return_number: string;
  date: string;
  customer_id: number;
  customer_name: string;
  customer_code: string;
  invoice_id: number | null;
  invoice_number: string | null;
  cost_center_id: number | null;
  warehouse_id: number | null;
  warehouse_name: string | null;
  currency_code: string;
  exchange_rate: string;
  reason: string | null;
  reason_ar: string | null;
  notes: string | null;
  notes_ar: string | null;
  subtotal: string;
  discount_amount: string;
  tax_amount: string;
  total: string;
  status: 'draft' | 'pending_approval' | 'approved' | 'posted' | 'cancelled';
  journal_entry_id: number | null;
  cogs_journal_entry_id: number | null;
  items: SalesReturnItem[];
  created_by: number | null;
  created_by_name: string | null;
  approved_by: number | null;
  approved_at: string | null;
  approved_by_name: string | null;
  posted_by: number | null;
  posted_at: string | null;
  cancelled_by: number | null;
  cancelled_at: string | null;
  cancellation_reason: string | null;
  created_at: string;
  updated_at: string;
}

export interface CreateSalesReturn {
  date: string;
  customer_id: number;
  invoice_id?: number | null;
  return_type?: 'invoice' | 'standalone';
  branch_id?: number;
  cost_center_id?: number | null;
  warehouse_id?: number | null;
  currency_code?: string;
  exchange_rate?: number;
  reason?: string | null;
  reason_ar?: string | null;
  notes?: string | null;
  notes_ar?: string | null;
  items: SalesReturnItemPayload[];
}

export interface UpdateSalesReturn extends Partial<CreateSalesReturn> {}
