#!/bin/bash

# API base URL
API_BASE_URL="http://localhost:8080" # Replace with your actual API base URL

# Box ID
BOX_ID=96 # Replace with the actual box ID

# Login credentials
USERNAME="boxuser" # Replace with your actual username
PASSWORD="boxuser" # Replace with your actual password

# Item data
ITEM_NAME="New Item"
ITEM_DESCRIPTION="This is a new item"

# Get a new JWT token
TOKEN=$(curl -s -X POST -H "Content-Type: application/json" \
  -d "{\"username\":\"$USERNAME\", \"password\":\"$PASSWORD\"}" \
  "$API_BASE_URL/login" | jq -r '.token')

# Create the item data in JSON format
ITEM_DATA=$(echo "{\"name\":\"$ITEM_NAME\",\"description\":\"$ITEM_DESCRIPTION\",\"box_id\":$BOX_ID}" | jq -r '.')

# Add the item to the box using the obtained token
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "$ITEM_DATA" \
  "$API_BASE_URL/items"
