// ─── GRN Item ───────────────────────────────────────────────────

export interface PurchaseGrnItem {
  id: number;
  purchase_grn_id: number;
  purchase_order_item_id: number | null;
  product_id: number;
  product_name: string;
  product_sku: string;
  product_variant_id: number | null;
  unit_id: number;
  unit_name: string;
  description: string | null;
  description_ar: string | null;
  quantity: string;
  accepted_quantity: string | null;
  rejected_quantity: string | null;
  stock_quantity: number;
  unit_cost: string;
  total_cost: string;
  batch_number: string | null;
  expiry_date: string | null;
  serial_numbers: string | null;
  rejection_reason: string | null;
  notes: string | null;
  sort_order: number;
}

export interface PurchaseGrnItemPayload {
  product_id: number;
  product_variant_id?: number | null;
  unit_id: number;
  order_item_id?: number | null;
  description?: string | null;
  description_ar?: string | null;
  quantity: number;
  unit_cost: number;
  batch_number?: string | null;
  expiry_date?: string | null;
  serial_numbers?: string | null;
  notes?: string | null;
  sort_order?: number;
}

// ─── GRN ────────────────────────────────────────────────────────

export interface PurchaseGrn {
  id: number;
  grn_number: string;
  date: string;
  purchase_order_id: number | null;
  purchase_order_number: string | null;
  warehouse_id: number;
  warehouse_name: string;
  supplier_id: number;
  supplier_name: string;
  supplier_code: string;
  status: 'draft' | 'approved' | 'cancelled';
  reference: string | null;
  notes: string | null;
  notes_ar: string | null;
  quality_notes: string | null;
  total_quantity: string;
  total_cost: string;
  inventory_receipt_id: number | null;
  items: PurchaseGrnItem[];
  created_by: number | null;
  created_by_name: string | null;
  approved_by: number | null;
  approved_at: string | null;
  approved_by_name: string | null;
  quality_checked_by: number | null;
  quality_checked_at: string | null;
  cancelled_by: number | null;
  cancelled_at: string | null;
  cancellation_reason: string | null;
  created_at: string;
  updated_at: string;
}

export interface CreatePurchaseGrn {
  date: string;
  purchase_order_id?: number | null;
  supplier_id: number;
  warehouse_id: number;
  reference?: string | null;
  notes?: string | null;
  notes_ar?: string | null;
  items: PurchaseGrnItemPayload[];
}

export interface UpdatePurchaseGrn extends Partial<CreatePurchaseGrn> {}
