#!/usr/bin/env bash
#
# duplicate-api.sh
#
function init_duplicate {
  declare -g _entries_json_='{}'
}

function add_for_duplicate {
  local -r _key_="$1"
  local -r _id_="$2"

  _entries_json_="$(
    jq -c --arg key "${_key_}" --arg id "${_id_}" '.[$key] |= .+ [ $id ]' <<<"${_entries_json_}"
    )" || return $?
}

function finalize_duplicate {
  _entries_json_="$(
    jq '[ to_entries[] | select( .value | length >1 ) ] | from_entries' <<<"${_entries_json_}"
    )" || return $?
}
