#! /bin/bash
KEY_FILE1=".api-key1"
KEY_FILE2=".api-key2"
JACAMO="/usr/bin/jacamo"

clear
if [[ ! -f "$JACAMO" ]] 
then
    echo "The computer hasn't JaCaMo!"
    echo "Installing dependencies..."
    sleep 3
    echo "deb [trusted=yes] http://packages.chon.group/ chonos main" | sudo tee /etc/apt/sources.list.d/chonos.list
    sudo apt update
    sudo apt install jacamo-cli
    
else
    echo "The computer has JaCaMo"
fi


if [ ! -f "$KEY_FILE1" ]; then
  echo ""
  echo "First you need to create an API_KEY at: https://twitterapi.io/dashboard"
  echo "After create, please press ENTER"
  read

  echo -n "Inform your Twitter API_KEY: "
  read API

  echo "$API" > "$KEY_FILE1"
else
  API=$(cat "$KEY_FILE1")
fi

echo "Using Twitter API-KEY=$API"
sed -i "s|private static final String API_KEY = \".*\";|private static final String API_KEY = \"$API\";|" src/main/java/env/TwitterArtifact.java


if [ ! -f "$KEY_FILE2" ]; then
  echo ""
  echo "Second you need to create an API_KEY at: https://aistudio.google.com/api-keys"
  echo "After create, please press ENTER"
  read

  echo -n "Inform your Google AI Studio API_KEY: "
  read API2

  echo "$API2" > "$KEY_FILE2"
else
  API2=$(cat "$KEY_FILE2")
fi

sed -i "s|private static final String API_KEY = \".*\";|private static final String API_KEY = \"$API2\";|" src/main/java/env/SentimentArtifact.java

jacamo tcc_ia_jacamo.jcm


sed -i "s|private static final String API_KEY = \".*\";|private static final String API_KEY = \"NONE\";|" src/main/java/env/TwitterArtifact.java
sed -i "s|private static final String API_KEY = \".*\";|private static final String API_KEY = \"NONE\";|" src/main/java/env/SentimentArtifact.java
