#!/bin/bash
# Pickle Motivation Generator for Stevan Woska
# Generates unique motivational messages + pickle jokes

# Get Stevan's contact info from first argument or use default
STEVAN_CONTACT="${1:-}"  # Will be passed by cron

if [[ -z "$STEVAN_CONTACT" ]]; then
  echo "Error: No contact info provided"
  exit 1
fi

# Store history to avoid repeats
HISTORY_FILE="$HOME/.clawdbot/workspace/pickle_history.txt"
mkdir -p "$(dirname "$HISTORY_FILE")"
touch "$HISTORY_FILE"

# Generate a date-based seed for uniqueness
DATE_SEED=$(date +%Y%m%d)
SEED=$(( $(date +%s) / 86400 ))  # Changes daily

# Arrays of content to mix and match
MOTIVATION=(
  "You've got this, Stevan!"
  "Keep crushing it, my friend!"
  "Today's the day to make it happen!"
  "You're on fire right now!"
  "Nothing can stop you today!"
  "Rise and grind, legend!"
  "Your potential is limitless!"
  "Stay focused, stay hungry!"
  "Every day is a fresh start!"
  "You're stronger than you think!"
  "Believe in yourself always!"
  "Progress, not perfection!"
  "You're doing amazing things!"
  "Keep pushing forward!"
  "Success is coming your way!"
  "Trust the process!"
  "You've got the power!"
  "Make today count!"
  "Your time is now!"
  "You're unstoppable!"
  "Dream big, work hard!"
  "Consistency is key!"
  "One step at a time!"
  "You're built for this!"
  "Keep your eyes on the prize!"
  "The world needs what you've got!"
)

PICKLE_SETUP=(
  "Speaking of pickles..."
  "Fun pickle fact:"
  "Random pickle thought:"
  "Here's a pickle joke for you:"
  "Pickle wisdom incoming:"
  "Did you know about pickles?"
  "Pickle time:"
  "Get this - about pickles:"
  "Bringing the pickle energy:"
  "Quick pickle interlude:"
  "Pickle break:"
  "Why are pickles so funny?"
  "Pickle moment:"
  "Here comes the pickle:"
  "Pickle vibes:"
  "Pickles are wild:"
  "Fun with pickles:"
  "Pickle appreciation:"
  "Quick pickle story:"
  "Pickles, man..."
  "Here's the thing about pickles:"
  "Pickle knowledge drop:"
  "Pickle thoughts:"
  "Pickle-powered message:"
  "Never forget about pickles:"
)

PICKLE_PUNCHLINES=(
  "What do you call a pickle that's always complaining? A sour-puss."
  "Why did the pickle go to the gym? To get a little more jacked...err, pickled."
  "What's a pickle's favorite music? Pickle-pop, duh."
  "Why are pickles so good at solving problems? They're always in a pickle, but they get out of it."
  "What do you call a frozen pickle? A pickle-sicle."
  "Why did the cucumber apply for a job? It wanted to become a pickle - it's a real career move."
  "What's a pickle's favorite TV show? Brining Bad."
  "Why are pickles such good friends? They're always there when you're in a jam...or jar."
  "What do you call a famous pickle? A dill-lebrity."
  "Why don't pickles ever get lost? They always know their brine."
  "What's a pickle's life philosophy? When life gives you cucumbers, pickle 'em."
  "Why did the pickle cross the road? To prove he wasn't chicken."
  "What do you call a pickle who's a detective? Sherlock Holmes...with a crunch."
  "Why are pickles so optimistic? They always look on the brine side."
  "What's a pickle's favorite day of the week? Fri-dill of course."
  "Why did the pickle get promoted? He was a big dill."
  "What do you call a sad pickle? A weeping brine."
  "Why are pickles so honest? They're always straightforward - no waffling like cucumbers."
  "What's a pickle's favorite type of investment? A brine-y portfolio."
  "Why did the pickle break up with the cucumber? He needed someone with more...preservation."
  "What do you call a pickle who works in IT? A tech-dill-ogist."
  "Why are pickles so resilient? They've been through a lot - literally submerged and came out crunchier."
  "What's a pickle's favorite sport? Anything they can pickle-ball at."
  "Why don't pickles ever tell secrets? They're always well-preserved."
  "What do you call a pickle who's always late? A procrastini-cucumber."
  "Why are pickles such good negotiators? They know how to pick their battles...and jars."
  "What's a pickle's favorite holiday? Christmas, because of the pickles in their stocking...wait."
  "Why did the pickle start a podcast? To spread some brine-tastic content."
  "What do you call a pickle that's really stressed? A dill-lemma."
  "Why are pickles so calm under pressure? They've been in tighter spots."
  "What's a pickle's favorite animal? A dill-phin, obviously."
  "Why don't pickles ever give up? They're always in it for the long brine."
  "What do you call a pickle who's always showing off? A pickle flexer."
  "Why are pickles so supportive? They always relish your wins."
  "What's a pickle's favorite social media? Tik-Pickle."
  "Why did the pickle go to therapy? It had some unresolved jar issues."
  "What do you call a pickle who's great at math? A calcu-dill-ator."
  "Why are pickles so popular? They're a big dill."
  "What's a pickle's favorite movie genre? Dill-mas."
  "Why did the pickle get a tattoo? It wanted to show it had some...bravery."
  "What do you call a pickle who's always cold? A frozen pickle situation."
  "Why are pickles so philosophical? They ponder the brine-ing questions."
)

# Calculate indices using the seed
MOTIVATION_IDX=$(( SEED % ${#MOTIVATION[@]} ))
SETUP_IDX=$(( (SEED * 3) % ${#PICKLE_SETUP[@]} ))
PUNCHLINE_IDX=$(( (SEED * 7) % ${#PICKLE_PUNCHLINES[@]} ))

# Build the message
MOTIVATION_PART="${MOTIVATION[$MOTIVATION_IDX]}"
SETUP_PART="${PICKLE_SETUP[$SETUP_IDX]}"
PUNCHLINE_PART="${PICKLE_PUNCHLINES[$PUNCHLINE_IDX]}"

MESSAGE="${MOTIVATION_PART} ${SETUP_PART} ${PUNCHLINE_PART}"

# Check if this exact message was sent before (prevent repeats)
if grep -Fq "$MESSAGE" "$HISTORY_FILE" 2>/dev/null; then
  # Shift the indices if we've seen this combo
  SHIFT=1
  while true; do
    NEW_MOTIVATION_IDX=$(( (MOTIVATION_IDX + SHIFT) % ${#MOTIVATION[@]} ))
    NEW_SETUP_IDX=$(( (SETUP_IDX + SHIFT) % ${#PICKLE_SETUP[@]} ))
    NEW_PUNCHLINE_IDX=$(( (PUNCHLINE_IDX + SHIFT) % ${#PICKLE_PUNCHLINES[@]} ))

    NEW_MOTIVATION="${MOTIVATION[$NEW_MOTIVATION_IDX]}"
    NEW_SETUP="${PICKLE_SETUP[$NEW_SETUP_IDX]}"
    NEW_PUNCHLINE="${PICKLE_PUNCHLINES[$NEW_PUNCHLINE_IDX]}"

    NEW_MESSAGE="${NEW_MOTIVATION} ${NEW_SETUP} ${NEW_PUNCHLINE}"

    if ! grep -Fq "$NEW_MESSAGE" "$HISTORY_FILE" 2>/dev/null; then
      MESSAGE="$NEW_MESSAGE"
      break
    fi

    SHIFT=$((SHIFT + 1))
    if [[ $SHIFT -gt 50 ]]; then
      break
    fi
  done
fi

# Log this message to history
echo "$(date +%Y-%m-%d): $MESSAGE" >> "$HISTORY_FILE"

# Send the message
imsg send --to "$STEVAN_CONTACT" --text "$MESSAGE"

echo "Sent pickle motivation to $STEVAN_CONTACT"
