#!/bin/bash

source /tmp/atlassian-setup/credentials.env

echo "=== Verifying Team Members in Atlassian ==="
echo ""

# List of expected team members
declare -a TEAM_MEMBERS=(
    "v.samoilenko@ai-impress.com"
    "p.gulyk@ai-impress.com"
    "o.maslovets@ai-impress.com"
    "s.klochok@ai-impress.com"
)

# Get all users from Jira
echo "Fetching users from Atlassian..."
USERS_JSON=$(curl -s -X GET \
  "${ATLASSIAN_SITE_URL}/rest/api/3/users/search" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json")

echo "Users in Atlassian:"
echo "$USERS_JSON" | python3 -c "
import sys, json
users = json.load(sys.stdin)
for user in users:
    print(f\"  - {user['emailAddress']} (ID: {user['accountId'][:8]}...)")
" 2>/dev/null || echo "Could not parse users"

echo ""
echo "Expected Team Members:"
for member in "${TEAM_MEMBERS[@]}"; do
    echo "  - $member"
done

echo ""
echo "Note: All team members should already be added to Atlassian Cloud instance"
echo "Site: ${ATLASSIAN_SITE_URL}"
