#!/bin/bash
USER=$(whoami)
GARDEN_HOMEDIR=/home/botanist/botany
ART_DIR=${GARDEN_HOMEDIR}/art

PLANT_JSON=$(cat .botany/${USER}_plant_data.json)
PLANT_GENERATION=$(echo ${PLANT_JSON} | jq -jr '.generation')
PLANT_DESCRIPTION=$(echo ${PLANT_JSON} | jq .description | tr -d '"')
PLANT_AGE=$(echo ${PLANT_JSON} | jq .age | tr -d '"')
PLANT_STAGE=$(echo ${PLANT_JSON} | jq .stage | tr -d '"')

if [ $(echo ${PLANT_JSON} | jq .is_dead) == 'false' ]; then
	PLANT_STATUS=alive
else
	PLANT_STATUS=dead
fi

if [ ${PLANT_STATUS} == dead ]; then
	PLANT_IMG=$(cat ${ART_DIR}/rip.txt)
elif [ ${PLANT_STAGE} == "seed" ]; then
	PLANT_IMG=$(cat ${ART_DIR}/seedling.txt)
elif [ ${PLANT_STAGE} = "seedling" ]; then
	PLANT_IMG=$(cat ${ART_DIR}/seedling.txt)
else 
	PLANT_SPECIES=$(echo ${PLANT_JSON} | jq .species | tr -d '"')
	if [ ${PLANT_STAGE} = "young" ]; then
		PLANT_IMG=$(cat ${ART_DIR}/${PLANT_SPECIES}1.txt)
	elif [ ${PLANT_STAGE} = "mature" ]; then
		PLANT_IMG=$(cat ${ART_DIR}/${PLANT_SPECIES}2.txt)
	elif [ ${PLANT_STAGE} = "flowering" ]; then
		PLANT_IMG=$(cat ${ART_DIR}/${PLANT_SPECIES}3.txt)
	elif [ ${PLANT_STAGE} = "seed-bearing" ]; then
		PLANT_IMG=$(cat ${ART_DIR}/${PLANT_SPECIES}2.txt)
	fi
fi

VISITORS=$(sqlite3 ${GARDEN_HOMEDIR}/sqlite/garden_db.sqlite "select visitor_name from visitors where garden_name = 'Asara';" | xargs | sed -e 's/ /, /g')


cat << EOF
<plaintext>WELCOME TO MY TILDE PAGE
This is updated daily!
Here is the status of my botany plant!
My generation #${PLANT_GENERATION} ${PLANT_DESCRIPTION} is currently ${PLANT_STATUS}.
${PLANT_IMG}

Thanks to the following friends for watering my plant:
$(for i in ${VISITORS}; do echo $i; done)
EOF

