#!/bin/bash
# Run crop messaging analysis (06_crop_messaging)
# Usage: ./06_run_crop_messaging.sh --current_week=<week_num> --previous_week=<week_num> --estate_name=<name>

current_week=$(date +%V)  # Current ISO week number
previous_week=$((current_week - 1))
estate_name="aura"

for arg in "$@"; do
    case $arg in
        --current_week=*)
            current_week="${arg#*=}"
            ;;
        --previous_week=*)
            previous_week="${arg#*=}"
            ;;
        --estate_name=*)
            estate_name="${arg#*=}"
            ;;
        *)
            echo "Unknown option: $arg"
            exit 1
            ;;
    esac
    shift
done

echo "Running crop messaging analysis for $estate_name: week $previous_week → week $current_week."
cd r_app
Rscript 06_crop_messaging $current_week $previous_week $estate_name
cd ..
