#!/usr/bin/env bash
set -e

source scripts/str_lib.sh

UV_URL="https://astral.sh/uv/install.sh"

install_uv() {
  message "warning" "UV is not available"
  while true; do
    read -p "- Do you wish to install this program? (Y/N/q): " yn
    case $yn in
    [Yy]*)
      curl -LsSf $UV_URL | sh
      message "success" "UV installation completed ($(uv --version))"
      break
      ;;
    [Nn]*)
      message "error" "UV will not be installed"
      message "warning" "The development team recommends the installation of UV for the packaging and management of dependencies"
      exit
      ;;
    [q]*)
      exit
      ;;
    *) message "Please answer yes (Y) or no (N)" ;;
    esac
  done
}

check() {
  message "info" "Check dependencies"
  if ! (command -v uv &>/dev/null); then
    install_uv
  else
    message "success" "UV is available ($(uv --version))"
  fi
}

if [[ "${#BASH_SOURCE[@]}" -eq 1 ]]; then
  check "$@"
fi
