module JSONAPI::Serialization::IncludePathHelpers

def include_paths_to_relationship_names(include_paths, path_prefix)

def include_paths_to_relationship_names(include_paths, path_prefix)
  return [] if include_paths.blank?
  prefix = path_prefix.present? ? "#{path_prefix}." : ""
  include_paths.filter_map do |p|
    path = p.to_s
    next unless path == path_prefix || path.start_with?(prefix)
    segments = path.split(".")
    prefix_segments = path_prefix.split(".")
    next if segments.length <= prefix_segments.length
    segments[prefix_segments.length].to_sym
  end.uniq
end

def normalize_include_paths(include_param)

def normalize_include_paths(include_param)
  case include_param
  when Array
    include_param.flat_map { |s| s.to_s.split(",").map(&:strip) }.uniq
  when String
    include_param.split(",").map(&:strip)
  else
    []
  end
end