class Dscf::Marketplace::RfqItem

def self.ransackable_associations(_auth_object = nil)

def self.ransackable_associations(_auth_object = nil)
  %w[request_for_quotation product unit quotation_items]
end

def self.ransackable_attributes(_auth_object = nil)

Ransack configuration for secure filtering
def self.ransackable_attributes(_auth_object = nil)
  %w[id request_for_quotation_id product_id unit_id quantity notes created_at updated_at]
end

def has_quotations?

def has_quotations?
  quotation_items.exists?
end

def highest_quoted_price

def highest_quoted_price
  quotation_items.where.not(unit_price: nil).maximum(:unit_price)
end

def lowest_quoted_price

def lowest_quoted_price
  quotation_items.where.not(unit_price: nil).minimum(:unit_price)
end

def product_name

def product_name
  product&.name
end

def product_sku

def product_sku
  product&.sku
end

def quotation_count

def quotation_count
  quotation_items.count
end

def quoted_price_range

def quoted_price_range
  return nil unless has_quotations?
  low = lowest_quoted_price
  high = highest_quoted_price
  return low if low == high
  "#{low} - #{high}"
end

def total_requested_quantity

def total_requested_quantity
  return nil unless quantity && unit
  # Convert to base unit for comparison if needed
  quantity
end

def unit_code

def unit_code
  unit&.code
end

def unit_compatible_with_product

def unit_compatible_with_product
  return unless product_id && unit_id
  unless product.unit_id == unit_id
    errors.add(:unit_id, "must match the product's base unit")
  end
end

def unit_name

def unit_name
  unit&.name
end