#!/bin/sh

rm -rf test_files
mkdir -p test_files

# Copy user-provided example files from examples/ directory
if [ -d "examples" ]; then
    # Copy JPEG files
    find examples -iname "*.jpg" -o -iname "*.jpeg" | head -1 | \
        xargs -I {} cp {} test_files/example.jpg 2>/dev/null

    # Copy ARW files
    find examples -iname "*.arw" | head -1 | \
        xargs -I {} cp {} test_files/example.arw 2>/dev/null

    # Copy MP4 files
    find examples -iname "*.mp4" | head -1 | \
        xargs -I {} cp {} test_files/example.mp4 2>/dev/null

    # Set old timestamps on copied files so they're not flagged as recent
    touch -t 202001010000 test_files/example.jpg 2>/dev/null
    touch -t 202001010000 test_files/example.arw 2>/dev/null
    touch -t 202001010000 test_files/example.mp4 2>/dev/null
fi

# Create synthetic ARW files with embedded timestamps
# Format: binary data with "YYYY:MM:DD HH:MM:SS" pattern
create_arw_with_timestamp() {
    local filename=$1
    local timestamp=$2
    printf '\x00\x00\x00\x00SONY\x00\x00' > "$filename"
    printf "$timestamp" >> "$filename"
    printf '\x00\x00\x00\x00TRAILER\x00' >> "$filename"
}

create_arw_with_timestamp "test_files/2020-01-15.arw" "2020:01:15 10:30:45"
create_arw_with_timestamp "test_files/2023-12-25.arw" "2023:12:25 08:15:00"

# Set old timestamps on ARW files so they're not flagged as recent
touch -t 202001150000 test_files/2020-01-15.arw
touch -t 202312250000 test_files/2023-12-25.arw

# ARW without valid timestamp
printf 'NO_VALID_TIMESTAMP_HERE_12345678' > test_files/no_timestamp.arw
touch -t 202001010000 test_files/no_timestamp.arw

# Create time-sensitive test files
touch -t 202001010000 test_files/old.jpg
touch test_files/recent.jpg  # Current time, <60s ago

# Create file for boundary testing - just use an old timestamp for now
touch -t 202001010000 test_files/boundary.jpg

# Unknown file type
touch test_files/unknown.xyz

# Create test file for timestamp updates
touch test_files/test_timestamp.txt
