#! /bin/bash
YARN="/usr/local/bin/yarn"
KEY_FILE1=".api-key1"
KEY_FILE2=".api-key2"


clear
if [[ ! -f "$YARN" ]] 
then
    echo "The computer hasn't YARN"
    echo "Installing dependencies..."
    sleep 3
    sudo apt install npm
    sudo npm install -g yarn
else
    echo "The computer has YARN"
fi


if [ ! -f "$KEY_FILE1" ]; then
  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|\"X-API-Key\": \".*\"|\"X-API-Key\": \"$API\"|" src/artifacts/tweetCollectorArtifact.ts


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

echo "Using Gemini API-KEY=$API2"
sed -i "s|apiKey: \".*\",|apiKey: \"$API2\",|" src/artifacts/sentimentAnalysisArtifact.ts

yarn install    
yarn dev


sed -i "s|\"X-API-Key\": \".*\"|\"X-API-Key\": \"NONE\"|" src/artifacts/tweetCollectorArtifact.ts
sed -i "s|apiKey: \".*\",|apiKey: \"NONE\",|" src/artifacts/sentimentAnalysisArtifact.ts
