#!/bin/bash

end_date="2024-06-08"
offset=7
data_dir="chemba"
file_name_tif="week_03_2024.tif"

# Parse command line arguments
for arg in "$@"; do
    case $arg in
        --offset=*)
            offset="${arg#*=}"
            ;;
        --end_date=*)
            end_date="${arg#*=}"
            ;;
        --data_dir=*)
            data_dir="${arg#*=}"
            ;;
        --file_name_tif=*)
            file_name_tif="${arg#*=}"
            ;;
        *)
            echo "Unknown option: $arg"
            exit 1
            ;;
    esac
    shift
done

echo "offset: $offset"
echo "end_date: $end_date"

# Check if required arguments are set
if [ -z "$end_date" ] || [ -z "$data_dir" ] || [ -z "$offset" ] || [ -z "$file_name_tif" ]; then
    echo "Missing arguments. Use: build_mosiac.sh --endate=2024-01-01 --offset=7 --data_dir=chemba --file_name_tif=week_03_2024.tif"
    exit 1
fi

echo mosaic_creation.R $end_date $offset $data_dir $file_name_tif

cd ../r_app
Rscript mosaic_creation.R $end_date $offset $data_dir $file_name_tif