#!/bin/bash
# Default values
TASK=""
MODEL="mistralai/Mistral-7B-Instruct-v0.2"
SAMPLE_SIZES="100"
VALIDATION_SETS="long"
BASE_PROMPT="base_prompt.txt"
VALIDATION_SIZE="100"
RESULTS_DIR="results"
MIN_LONG_VALIDATION_LENGTH=""
SEED=42  # Default seed value
SUBSTITUTE_TOKENS=""  # Default empty (flag not set)
NORMAL_TOKENS=""  # Default empty (flag not set)

# Parse command line arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        --language)
            LANGUAGE="$2"
            shift 2
            ;;
        --model)
            MODEL="$2"
            shift 2
            ;;
        --sample_sizes)
            SAMPLE_SIZES="$2"
            shift 2
            ;;
        --validation_sets)
            VALIDATION_SETS="$2"
            shift 2
            ;;
        --prompt_template)
            PROMPT_TEMPLATE="$2"
            shift 2
            ;;
        --validation_size)
            VALIDATION_SIZE="$2"
            shift 2
            ;;
        --results_dir)
            RESULTS_DIR="$2"
            shift 2
            ;;
        --encoding_technique)
            ENCODING_TECHNIQUE="$2"
            shift 2
            ;;
        --seed)
            SEED="$2"
            shift 2
            ;;
        *)
            echo "Unknown parameter: $1"
            exit 1
            ;;
    esac
done

if [[ -z "$ENCODING_TECHNIQUE" ]]; then
    echo "Error: encoding_technique is required"
    #echo "Usage: $0 --task <task> --model <model> --base_prompt <template> [options]"
    exit 1
fi

if [[ -z "$LANGUAGE" || -z "$MODEL" || -z "$PROMPT_TEMPLATE" || -z "$ENCODING_TECHNIQUE" ]]; then
    echo "Error: Required parameters missing"
    echo "Usage: $0 --task <task> --model <model> --base_prompt <template> [options]"
    echo "Options:"
    echo "  --language <language>     Language for the task (default: en)"
    echo "  --model <model>           Model to use (default: deepseek-chat,grok-2,claude)"
    echo "  --prompt_template <template>  Prompt template (default: io_prompt)"
    echo "  --sample_sizes <sizes>     Comma-separated list of sample sizes (default: 3,5,10)"
    echo "  --validation_sets <sets>   Comma-separated list of validation sets (default: short,long)"
    echo "  --validation_size <size>   Number of validation examples (default: 100)"
    echo "  --seed <seed>             Random seed for reproducibility (default: 42)"
    exit 1
fi

# Create job files for each combination
IFS=',' read -ra SIZES <<< "$SAMPLE_SIZES"
IFS=',' read -ra VAL_SETS <<< "$VALIDATION_SETS"

for size in "${SIZES[@]}"; do
    for val_set in "${VAL_SETS[@]}"; do
        # Create unique job file for each combination
        # Construct command for this combination

        echo "Creating job file for sample size $size and validation set $val_set and substituting tokens"
        CMD="python -m scripts.experiment \
            --language $LANGUAGE \
            --model $MODEL \
            --sample_sizes $size \
            --validation_sets $val_set \
            --prompt_template $PROMPT_TEMPLATE \
            --encoding_technique $ENCODING_TECHNIQUE \
            --seed $SEED "
            
        # Add optional parameters
        if [[ ! -z "$VALIDATION_SIZE" ]]; then
            CMD="$CMD --validation_size $VALIDATION_SIZE"
        fi
        # Save command to job file
        eval $CMD
    done
done


