#!/usr/bin/env bash
# shellcheck shell=bash

set -e

# Colors and formatting
GREEN='\033[1;32m'
BLUE='\033[1;34m'
NC='\033[0m' # No Color

function ok() {
  echo -e "${BOLD}${GREEN}[OK]${NC} ${BLUE}$1${NC} ${BOLD}${2:-}${NC}"
}

function install::pre_commit() {
  if ! command -v pre-commit &>/dev/null; then
    echo "Installing pre-commit..."
    brew install pre-commit
  fi

  # Check if pre-commit hooks are already installed
  if [ ! -f ".git/hooks/pre-commit" ]; then
    echo "Setting up pre-commit hooks..."
    pre-commit install -f
  fi

  ok "pre-commit" "$(pre-commit --version | cut -d' ' -f2)"
}

function install::swiftlint() {
  ok "swiftlint" "$(./scripts/swiftlint --version)"
}

function install::swiftformat() {
  ok "swiftformat" "$(./scripts/swiftformat --version)"
}

function main() {
  install::swiftlint
  install::swiftformat
  install::pre_commit
}

# Execute main function
main
