#!/bin/bash
# Default values
MODEL="deepseek-chat"
RESULTS_DIR="results"
SEED=42
NUM_TEST_SAMPLES=100

# Parse command line arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        --language)
            LANGUAGE="$2"
            shift 2
            ;;
        --model)
            MODEL="$2"
            shift 2
            ;;
        --prompt_template)
            PROMPT_TEMPLATE="$2"
            shift 2
            ;;
        --encoding_technique)
            ENCODING_TECHNIQUE="$2"
            shift 2
            ;;
        --seed)
            SEED="$2"
            shift 2
            ;;
        --k)
            K="$2"
            shift 2
            ;;
        --base_path)
            BASE_PATH="$2"
            shift 2
            ;;
        --num_test_samples)
            NUM_TEST_SAMPLES="$2"
            shift 2
            ;;
        *)
            echo "Unknown parameter: $1"
            exit 1
            ;;
    esac
done

if [[ -z "$ENCODING_TECHNIQUE" ]]; then
    echo "Error: encoding_technique is required"
    exit 1
fi
if [[ -z "$BASE_PATH" ]]; then
    BASE_PATH="results"
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 to test"
    echo "  --model <model>           Model to use (default: deepseek-chat)"
    echo "  --prompt_template <template>  Prompt template (default: io_prompt)"
    echo "  --seed <seed>             Random seed for reproducibility (default: 42)"
    exit 1
fi

case $MODEL in
    deepseek-chat)
        echo "Running DeepSeek workflow..."
        CMD="python -m src.deepseek.experiment_deepseek \
            --language $LANGUAGE \
            --model $MODEL \
            --prompt_template $PROMPT_TEMPLATE \
            --encoding_technique $ENCODING_TECHNIQUE \
            --tokenizer_path ./src/deepseek/$MODEL \
            --seed $SEED \
            --k $K \
            --base_path $BASE_PATH \
            --num_test_samples $NUM_TEST_SAMPLES"
        eval $CMD
        ;;


    deepseek-reasoner)
        echo "Running DeepSeek workflow..."
        CMD="python -m src.deepseek.experiment_deepseek \
            --language $LANGUAGE \
            --model $MODEL \
            --prompt_template $PROMPT_TEMPLATE \
            --encoding_technique $ENCODING_TECHNIQUE \
            --tokenizer_path ./src/deepseek/$MODEL \
            --seed $SEED \
            --k $K \
            --base_path $BASE_PATH \
            --num_test_samples $NUM_TEST_SAMPLES"
        eval $CMD
        ;;

    *)
        echo "Error: Invalid model. Must be one of: deepseek-chat, deepseek-reasoner"
        show_usage
        exit 1
        ;;
esac

