#!/bin/bash
# Enable Entra VerifiedID Service
# Provides step-by-step instructions and validates service status

set -euo pipefail

GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'

log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }

log_info "Entra VerifiedID Service Activation Guide"
echo ""

# Check if Azure CLI is available
if command -v az &> /dev/null && az account show &> /dev/null; then
    TENANT_ID=$(az account show --query tenantId -o tsv)
    SUBSCRIPTION_ID=$(az account show --query id -o tsv)
    
    log_info "Detected Azure subscription:"
    echo "  Tenant ID: ${TENANT_ID}"
    echo "  Subscription ID: ${SUBSCRIPTION_ID}"
    echo ""
fi

log_info "Step-by-Step Instructions to Enable Verified ID:"
echo ""
echo "1. Open Azure Portal: https://portal.azure.com"
echo "2. Navigate to: Azure Active Directory → Verified ID"
echo "   Direct link: https://portal.azure.com/#view/Microsoft_AAD_IAM/VerifiedIDBlade"
echo ""
echo "3. If Verified ID is not visible:"
echo "   a. Check if you have the required permissions (Global Administrator or Verified ID Administrator)"
echo "   b. Verify your Azure AD tenant supports Verified ID"
echo "   c. Some tenants may need to enable the feature first"
echo ""
echo "4. Click 'Get started' or 'Enable Verified ID'"
echo ""
echo "5. Wait for service activation (typically 5-10 minutes)"
echo ""
echo "6. Once enabled, you should see:"
echo "   - Credentials section"
echo "   - Issuance section"
echo "   - Settings section"
echo ""

# Try to check service status via Azure CLI (if possible)
log_info "Attempting to verify service status..."
if command -v az &> /dev/null && az account show &> /dev/null; then
    # Note: Azure CLI doesn't have direct Verified ID commands, but we can check if the service exists
    log_info "Azure CLI detected. Checking tenant capabilities..."
    
    # Check if we can access the tenant
    if az ad tenant show &> /dev/null; then
        log_success "Tenant access confirmed"
    fi
fi

log_info "After enabling Verified ID, run:"
echo "  ./scripts/deploy/create-credential-manifests.sh"
echo ""
log_success "Service activation guide complete!"

