#!/bin/bash

# Function to generate a random locally administered (private) MAC address
generate_random_mac() {
    # First byte: set locally administered bit (0x02) and unicast (0x00)
    # Remaining bytes: random
    printf '02:%02x:%02x:%02x:%02x:%02x\n' \
        $((RANDOM % 256)) \
        $((RANDOM % 256)) \
        $((RANDOM % 256)) \
        $((RANDOM % 256)) \
        $((RANDOM % 256))
}

# Check if the right number of arguments are given
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 <json_file_path> <amount>"
    exit 1
fi

# Assign arguments to variables
json_file="$1"
amount="$2"

# Check if jq is installed
if ! command -v jq >/dev/null 2>&1; then
    echo "Error: jq is required but not installed."
    exit 1
fi

# Check if JSON file exists
if [ ! -f "$json_file" ]; then
    echo "Error: File '$json_file' does not exist."
    exit 1
fi

# Validate JSON file content
jq empty "$json_file" 2>/dev/null
if [ $? -ne 0 ]; then
    echo "Error: Invalid JSON in file '$json_file'."
    exit 1
fi

# If valid, display JSON and amount
echo "Valid JSON detected!"
echo "Amount: $amount"

mac=$(generate_random_mac)
