#!/usr/bin/env bash

: <<'DOC'
Channel plugin for tools installed by the system package manager layer.

Requirements:
  version   preferred package version when supported by the host manager
  repo      per-manager third-party repo config (passed to system_packages_add_repo)
  needs     list of other system tools that must be installed first
DOC

function __system_channel__install() {
  local tool="$1"
  local requirements="$2"
  local version repo_json

  version=$(jq_get "$requirements" '.version' '')
  repo_json=$(jq_get "$requirements" '.repo' '')

  if jq_defined "$repo_json"; then
    system_packages_add_repo "$tool" "$repo_json"
  fi

  system_packages_install "$tool" "$version"
}

function __system_channel__uninstall() {
  local tool="$1"
  system_packages_remove "$tool"
}

register_channel \
  --name "system" \
  --installer __system_channel__install \
  --uninstaller __system_channel__uninstall
