
import matplotlib.pyplot as plt
import numpy as np

# --- Data Extraction ---
# This data was parsed from the article provided. It represents the major parent companies
# and the VPN services they own.
vpn_data = {
    "Kape Technologies": {
        "vpns": ["ExpressVPN", "CyberGhost", "Private Internet Access", "ZenMate", "Intego"],
        "country": "Isle of Man / UK",
        "notes": "Formerly Crossrider, accused of distributing adware.",
        "color": "red"
    },
    "Ziff Davis": {
        "vpns": ["IPVanish", "StrongVPN", "Encrypt.me", "SaferVPN", "Perimeter 81", "FastVPN", "VIPRE VPN", "Speedtest VPN", "netDNA"],
        "country": "USA",
        "notes": "Owns PCMag. Acquired many VPNs via StackPath.",
        "color": "blue"
    },
    "Aura (Pango)": {
        "vpns": ["Hotspot Shield", "TouchVPN", "JustVPN", "Betternet", "Ultra VPN", "VPN 360", "FigLeaf VPN", "Aura VPN"],
        "country": "USA",
        "notes": "Acquired AnchorFree and Betternet.",
        "color": "green"
    },
    "Gaditek": {
        "vpns": ["PureVPN", "Ivacy VPN", "Unblock VPN (defunct)", "OneVPN (likely)", "Atom (white-label)"],
        "country": "Pakistan",
        "notes": "Operates several VPN review websites.",
        "color": "purple"
    },
    "Nord Security": {
        "vpns": ["NordVPN", "Surfshark", "NordLayer"],
        "country": "Panama",
        "notes": "Merged with Surfshark in 2022.",
        "color": "orange"
    }
}

def create_vpn_ownership_diagram(data):
    """
    Generates a diagram that visually represents the complex ownership structure
    of the VPN market, styled to look like overlapping Venn diagrams.
    
    This function requires the 'matplotlib' and 'numpy' libraries.
    You can install them using: pip install matplotlib numpy
    """
    fig, ax = plt.subplots(figsize=(22, 16))
    ax.set_xlim(0, 100)
    ax.set_ylim(0, 100)
    ax.axis('off')

    # Define positions and radius for the main company circles
    positions = {
        "Kape Technologies": (30, 70),
        "Ziff Davis": (70, 70),
        "Aura (Pango)": (50, 40),
        "Gaditek": (20, 25),
        "Nord Security": (80, 25),
    }
    radius = 20

    # Draw each company's circle and populate it with data
    for company, details in data.items():
        center_x, center_y = positions[company]
        
        # Draw the main circle. Alpha is used for a nice overlapping effect.
        circle = plt.Circle((center_x, center_y), radius, color=details["color"], alpha=0.3)
        ax.add_artist(circle)
        
        # Add the company name above the circle
        ax.text(center_x, center_y + radius + 2, company, ha='center', va='center', fontsize=20, fontweight='bold')
        
        # Add the country of origin
        ax.text(center_x, center_y + radius - 2, f"({details['country']})", ha='center', va='center', fontsize=20, fontstyle='italic')

        # Add the list of VPNs inside the circle
        # Joining with newline characters for vertical list display
        vpn_list_str = "\n".join(details["vpns"])
        ax.text(center_x, center_y, vpn_list_str, ha='center', va='center', fontsize=24, wrap=True)

        # Add interesting notes from the article below the circle
        note_text = f"Note: {details['notes']}"
        ax.text(center_x, center_y + radius - 6, note_text, ha='center', va='bottom', fontsize=10, style='italic', wrap=True, 
                bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='black', lw=1, alpha=0.4))

    # Add a main title for the entire diagram
    fig.suptitle("VPN Ownership Landscape: A Web of Companies", fontsize=28, fontweight='bold')
    ax.set_title("Based on the article 'Hidden VPN Owners Unveiled'\nhttps://vpnpro.com/blog/hidden-vpn-owners-unveiled-97-vpns-23-companies/", fontsize=16, pad=20)
    
    # Save the figure to a file
    output_filename = "vpn_ownership_diagram.png"
    plt.savefig(output_filename, bbox_inches='tight', dpi=300)
    
    print(f"Diagram saved successfully as '{output_filename}'")

# --- Main execution ---
if __name__ == '__main__':
    create_vpn_ownership_diagram(vpn_data)
