#!/usr/bin/sh

# Text styles
bold=$(tput bold)
normal=$(tput sgr0)

# Checking for potential errors
check_command="ruff --config ruff.toml check"
echo "Running '$check_command'"
$check_command
status=$?
if [[ $status == "127" ]]; then
  echo "${bold}
╭─Commit─Aborted───────────────────────────────────────────────╮
│ Looks like you don't have ruff installed. This project uses  │
│ ruff to check formatting and look for potential errors.      │
│ To install ruff you can run 'pip install ruff'.              │
╰──────────────────────────────────────────────────────────────╯\
${normal}"
  exit $status
elif [[ $status != "0" ]]; then
  echo "${bold}
╭─Commit─Aborted─────────────────────────────────────────────╮
│ Found potential errors, please fix them before committing. │
│ To ignore the errors use '--no-verify'.                    │
╰────────────────────────────────────────────────────────────╯\
${normal}"
  exit $status
fi

# Checking formatting
check_command="ruff --config ruff.toml format --check"
echo "Running '$check_command'."
$check_command
status=$?
if [[ $status != "0" ]]; then
  echo "${bold}
╭─Commit─Aborted───────────────────────────────────────────────────────╮
│ Found formatting inconsistencies, please fix them before committing. │
│ To automatically fix formatting run 'ruff --config ruff.toml format' │
│ To ignore the errors use '--no-verify'.                              │
╰──────────────────────────────────────────────────────────────────────╯\
${normal}"
  exit $status
fi