#!/bin/bash

# Mobile API Test Script
# Replace TREELOGY_ID with your actual project ID from the database
# Example: If you have a project with treelogy_id=1, use that

TREELOGY_ID=1
BASE_URL="http://172.17.46.11:63318/api/mobile/project"

echo "================================"
echo "Testing Mobile APIs"
echo "================================"
echo ""

# 1. Test Login
echo "1. Testing /login..."
curl -X POST "${BASE_URL}/${TREELOGY_ID}/login" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "email=anilqc" \
  -d "password=40bd001563085fc35165329ea1ff5c5ecbdbbeef"
echo -e "\n"

# 2. Test Tree Details (Master Data)
echo "2. Testing /treedetails..."
curl -X POST "${BASE_URL}/${TREELOGY_ID}/treedetails" \
  -H "Content-Type: application/x-www-form-urlencoded"
echo -e "\n"

# 3. Test Get Enumerators
echo "3. Testing /getEnumerators..."
curl -X POST "${BASE_URL}/${TREELOGY_ID}/getEnumerators" \
  -H "Content-Type: application/x-www-form-urlencoded"
echo -e "\n"

# 4. Test Get Nearby Trees
echo "4. Testing /getNearbyTrees..."
curl -X POST "${BASE_URL}/${TREELOGY_ID}/getNearbyTrees" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "northLat=19.175641943211843" \
  -d "southLat=19.172044656788167" \
  -d "westLon=72.8424557195056" \
  -d "eastLon=72.84626428049437"
echo -e "\n"

# 5. Test Store Tree Details (minimal required fields)
echo "5. Testing /storetreedetails..."
curl -X POST "${BASE_URL}/${TREELOGY_ID}/storetreedetails" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "user_id=150" \
  -d "sq_id=44" \
  -d "tree_id=11" \
  -d "latitude=19.17478031787302" \
  -d "longitude=72.84467864781618" \
  -d "old_latitude=19.1744846" \
  -d "old_longitude=72.8441885" \
  -d "drag_distance=61.06885" \
  -d "othername=test tree" \
  -d "grith_cm=22222" \
  -d "height_mtr=33" \
  -d "canopy_dia_mtr=44" \
  -d "condition_id=1" \
  -d "remarks_id=4" \
  -d "other_remarks=test remarks" \
  -d "dist_frm_prev_tree=22" \
  -d "ownership_id=5" \
  -d "balImbalance_id=1" \
  -d "spatialcomment_id=2" \
  -d "societyname=test society" \
  -d "roadname=test road" \
  -d "birdnest=No" \
  -d "googleAddress=Test Address" \
  -d "entered_date=2025-01-25" \
  -d "entered_time=16:39:40" \
  -d "updated_date=2025-01-25" \
  -d "ward=1" \
  -d "is_within_boundary=0" \
  -d "version=1.0" \
  -d "image=0" \
  -d "image_leaves=0" \
  -d "image3=0" \
  -d "image4=0"
echo -e "\n"

echo "================================"
echo "All tests completed!"
echo "================================"

