#!/bin/bash
# Create a group as user1
source "$(dirname "$0")/config.sh"

TOKEN1=$(load_state "TOKEN1")
if [[ -z "$TOKEN1" ]]; then
    echo "ERROR: No token found. Run 02_login.sh first."
    exit 1
fi

echo "=== Creating group: $GROUP_NAME ==="
# Pipe curl directly to od to avoid null bytes being lost in bash variables
GROUP_ID=$(curl -s -X POST "$BASE_URL/new/group" \
    -d "token=$TOKEN1" \
    -d "name=$GROUP_NAME" \
    -d "color=$GROUP_COLOR" \
    | od -An -tu4 -N4 --endian=big | tr -d ' ')
echo "Group ID: $GROUP_ID"
save_state "GROUP_ID" "$GROUP_ID"
