#!/usr/bin/env python3
"""
Load German Universities (Hochschulen) as EduSearch Seeds.

Based on the HRK (Hochschulrektorenkonferenz) database, Germany has approximately:
- 120 Universities (Universitäten)
- 220 Universities of Applied Sciences (Fachhochschulen/HAW)
- 50 Art/Music Academies
- 100+ Private Universities

This script loads a comprehensive list of German higher education institutions.
"""

import httpx
import asyncio
import os

API_BASE = os.environ.get("LLM_GATEWAY_URL", "http://localhost:8000")

# =============================================================================
# GERMAN UNIVERSITIES (UNIVERSITÄTEN) - Public
# =============================================================================

UNIVERSITAETEN = [
    # ===== BADEN-WÜRTTEMBERG =====
    {"url": "https://www.uni-freiburg.de", "name": "Albert-Ludwigs-Universität Freiburg", "state": "BW"},
    {"url": "https://www.uni-heidelberg.de", "name": "Ruprecht-Karls-Universität Heidelberg", "state": "BW"},
    {"url": "https://www.uni-konstanz.de", "name": "Universität Konstanz", "state": "BW"},
    {"url": "https://www.uni-mannheim.de", "name": "Universität Mannheim", "state": "BW"},
    {"url": "https://www.uni-stuttgart.de", "name": "Universität Stuttgart", "state": "BW"},
    {"url": "https://www.kit.edu", "name": "Karlsruher Institut für Technologie (KIT)", "state": "BW"},
    {"url": "https://www.uni-tuebingen.de", "name": "Eberhard Karls Universität Tübingen", "state": "BW"},
    {"url": "https://www.uni-ulm.de", "name": "Universität Ulm", "state": "BW"},
    {"url": "https://www.uni-hohenheim.de", "name": "Universität Hohenheim", "state": "BW"},

    # ===== BAYERN =====
    {"url": "https://www.lmu.de", "name": "Ludwig-Maximilians-Universität München", "state": "BY"},
    {"url": "https://www.tum.de", "name": "Technische Universität München", "state": "BY"},
    {"url": "https://www.fau.de", "name": "Friedrich-Alexander-Universität Erlangen-Nürnberg", "state": "BY"},
    {"url": "https://www.uni-wuerzburg.de", "name": "Julius-Maximilians-Universität Würzburg", "state": "BY"},
    {"url": "https://www.uni-regensburg.de", "name": "Universität Regensburg", "state": "BY"},
    {"url": "https://www.uni-augsburg.de", "name": "Universität Augsburg", "state": "BY"},
    {"url": "https://www.uni-bamberg.de", "name": "Otto-Friedrich-Universität Bamberg", "state": "BY"},
    {"url": "https://www.uni-bayreuth.de", "name": "Universität Bayreuth", "state": "BY"},
    {"url": "https://www.uni-passau.de", "name": "Universität Passau", "state": "BY"},
    {"url": "https://www.ku.de", "name": "Katholische Universität Eichstätt-Ingolstadt", "state": "BY"},

    # ===== BERLIN =====
    {"url": "https://www.fu-berlin.de", "name": "Freie Universität Berlin", "state": "BE"},
    {"url": "https://www.hu-berlin.de", "name": "Humboldt-Universität zu Berlin", "state": "BE"},
    {"url": "https://www.tu-berlin.de", "name": "Technische Universität Berlin", "state": "BE"},
    {"url": "https://www.charite.de", "name": "Charité – Universitätsmedizin Berlin", "state": "BE"},

    # ===== BRANDENBURG =====
    {"url": "https://www.uni-potsdam.de", "name": "Universität Potsdam", "state": "BB"},
    {"url": "https://www.b-tu.de", "name": "Brandenburgische Technische Universität Cottbus-Senftenberg", "state": "BB"},
    {"url": "https://www.europa-uni.de", "name": "Europa-Universität Viadrina Frankfurt (Oder)", "state": "BB"},

    # ===== BREMEN =====
    {"url": "https://www.uni-bremen.de", "name": "Universität Bremen", "state": "HB"},
    {"url": "https://www.jacobs-university.de", "name": "Jacobs University Bremen", "state": "HB"},

    # ===== HAMBURG =====
    {"url": "https://www.uni-hamburg.de", "name": "Universität Hamburg", "state": "HH"},
    {"url": "https://www.tuhh.de", "name": "Technische Universität Hamburg", "state": "HH"},
    {"url": "https://www.hsu-hh.de", "name": "Helmut-Schmidt-Universität Hamburg", "state": "HH"},
    {"url": "https://www.hcu-hamburg.de", "name": "HafenCity Universität Hamburg", "state": "HH"},

    # ===== HESSEN =====
    {"url": "https://www.uni-frankfurt.de", "name": "Goethe-Universität Frankfurt am Main", "state": "HE"},
    {"url": "https://www.tu-darmstadt.de", "name": "Technische Universität Darmstadt", "state": "HE"},
    {"url": "https://www.uni-giessen.de", "name": "Justus-Liebig-Universität Gießen", "state": "HE"},
    {"url": "https://www.uni-marburg.de", "name": "Philipps-Universität Marburg", "state": "HE"},
    {"url": "https://www.uni-kassel.de", "name": "Universität Kassel", "state": "HE"},

    # ===== MECKLENBURG-VORPOMMERN =====
    {"url": "https://www.uni-rostock.de", "name": "Universität Rostock", "state": "MV"},
    {"url": "https://www.uni-greifswald.de", "name": "Universität Greifswald", "state": "MV"},

    # ===== NIEDERSACHSEN =====
    {"url": "https://www.uni-goettingen.de", "name": "Georg-August-Universität Göttingen", "state": "NI"},
    {"url": "https://www.uni-hannover.de", "name": "Leibniz Universität Hannover", "state": "NI"},
    {"url": "https://www.tu-braunschweig.de", "name": "Technische Universität Braunschweig", "state": "NI"},
    {"url": "https://www.tu-clausthal.de", "name": "Technische Universität Clausthal", "state": "NI"},
    {"url": "https://www.uni-oldenburg.de", "name": "Carl von Ossietzky Universität Oldenburg", "state": "NI"},
    {"url": "https://www.uni-osnabrueck.de", "name": "Universität Osnabrück", "state": "NI"},
    {"url": "https://www.uni-hildesheim.de", "name": "Universität Hildesheim", "state": "NI"},
    {"url": "https://www.leuphana.de", "name": "Leuphana Universität Lüneburg", "state": "NI"},
    {"url": "https://www.uni-vechta.de", "name": "Universität Vechta", "state": "NI"},
    {"url": "https://www.mh-hannover.de", "name": "Medizinische Hochschule Hannover", "state": "NI"},
    {"url": "https://www.tiho-hannover.de", "name": "Stiftung Tierärztliche Hochschule Hannover", "state": "NI"},

    # ===== NORDRHEIN-WESTFALEN =====
    {"url": "https://www.uni-koeln.de", "name": "Universität zu Köln", "state": "NW"},
    {"url": "https://www.uni-bonn.de", "name": "Rheinische Friedrich-Wilhelms-Universität Bonn", "state": "NW"},
    {"url": "https://www.uni-muenster.de", "name": "Westfälische Wilhelms-Universität Münster", "state": "NW"},
    {"url": "https://www.rwth-aachen.de", "name": "RWTH Aachen", "state": "NW"},
    {"url": "https://www.tu-dortmund.de", "name": "Technische Universität Dortmund", "state": "NW"},
    {"url": "https://www.ruhr-uni-bochum.de", "name": "Ruhr-Universität Bochum", "state": "NW"},
    {"url": "https://www.uni-due.de", "name": "Universität Duisburg-Essen", "state": "NW"},
    {"url": "https://www.hhu.de", "name": "Heinrich-Heine-Universität Düsseldorf", "state": "NW"},
    {"url": "https://www.uni-bielefeld.de", "name": "Universität Bielefeld", "state": "NW"},
    {"url": "https://www.uni-paderborn.de", "name": "Universität Paderborn", "state": "NW"},
    {"url": "https://www.uni-siegen.de", "name": "Universität Siegen", "state": "NW"},
    {"url": "https://www.uni-wuppertal.de", "name": "Bergische Universität Wuppertal", "state": "NW"},
    {"url": "https://www.fernuni-hagen.de", "name": "FernUniversität in Hagen", "state": "NW"},
    {"url": "https://www.dshs-koeln.de", "name": "Deutsche Sporthochschule Köln", "state": "NW"},

    # ===== RHEINLAND-PFALZ =====
    {"url": "https://www.uni-mainz.de", "name": "Johannes Gutenberg-Universität Mainz", "state": "RP"},
    {"url": "https://www.uni-trier.de", "name": "Universität Trier", "state": "RP"},
    {"url": "https://www.uni-koblenz.de", "name": "Universität Koblenz", "state": "RP"},
    {"url": "https://rptu.de", "name": "RPTU Kaiserslautern-Landau", "state": "RP"},

    # ===== SAARLAND =====
    {"url": "https://www.uni-saarland.de", "name": "Universität des Saarlandes", "state": "SL"},

    # ===== SACHSEN =====
    {"url": "https://www.tu-dresden.de", "name": "Technische Universität Dresden", "state": "SN"},
    {"url": "https://www.uni-leipzig.de", "name": "Universität Leipzig", "state": "SN"},
    {"url": "https://www.tu-chemnitz.de", "name": "Technische Universität Chemnitz", "state": "SN"},
    {"url": "https://tu-freiberg.de", "name": "TU Bergakademie Freiberg", "state": "SN"},

    # ===== SACHSEN-ANHALT =====
    {"url": "https://www.uni-halle.de", "name": "Martin-Luther-Universität Halle-Wittenberg", "state": "ST"},
    {"url": "https://www.ovgu.de", "name": "Otto-von-Guericke-Universität Magdeburg", "state": "ST"},

    # ===== SCHLESWIG-HOLSTEIN =====
    {"url": "https://www.uni-kiel.de", "name": "Christian-Albrechts-Universität zu Kiel", "state": "SH"},
    {"url": "https://www.uni-luebeck.de", "name": "Universität zu Lübeck", "state": "SH"},
    {"url": "https://www.uni-flensburg.de", "name": "Europa-Universität Flensburg", "state": "SH"},

    # ===== THÜRINGEN =====
    {"url": "https://www.uni-jena.de", "name": "Friedrich-Schiller-Universität Jena", "state": "TH"},
    {"url": "https://www.tu-ilmenau.de", "name": "Technische Universität Ilmenau", "state": "TH"},
    {"url": "https://www.uni-weimar.de", "name": "Bauhaus-Universität Weimar", "state": "TH"},
    {"url": "https://www.uni-erfurt.de", "name": "Universität Erfurt", "state": "TH"},
]

# =============================================================================
# FACHHOCHSCHULEN / HOCHSCHULEN FÜR ANGEWANDTE WISSENSCHAFTEN (HAW)
# =============================================================================

FACHHOCHSCHULEN = [
    # ===== BADEN-WÜRTTEMBERG =====
    {"url": "https://www.hs-aalen.de", "name": "Hochschule Aalen", "state": "BW"},
    {"url": "https://www.hs-albsig.de", "name": "Hochschule Albstadt-Sigmaringen", "state": "BW"},
    {"url": "https://www.hs-biberach.de", "name": "Hochschule Biberach", "state": "BW"},
    {"url": "https://www.hs-esslingen.de", "name": "Hochschule Esslingen", "state": "BW"},
    {"url": "https://www.hs-furtwangen.de", "name": "Hochschule Furtwangen", "state": "BW"},
    {"url": "https://www.hs-heilbronn.de", "name": "Hochschule Heilbronn", "state": "BW"},
    {"url": "https://www.hka.de", "name": "Hochschule Karlsruhe", "state": "BW"},
    {"url": "https://www.hs-kehl.de", "name": "Hochschule Kehl", "state": "BW"},
    {"url": "https://www.htwg-konstanz.de", "name": "HTWG Konstanz", "state": "BW"},
    {"url": "https://www.hs-ludwigsburg.de", "name": "Hochschule Ludwigsburg", "state": "BW"},
    {"url": "https://www.hs-mannheim.de", "name": "Hochschule Mannheim", "state": "BW"},
    {"url": "https://www.hdm-stuttgart.de", "name": "Hochschule der Medien Stuttgart", "state": "BW"},
    {"url": "https://www.hs-nueringen-geislingen.de", "name": "Hochschule für Wirtschaft und Umwelt Nürtingen-Geislingen", "state": "BW"},
    {"url": "https://www.hs-offenburg.de", "name": "Hochschule Offenburg", "state": "BW"},
    {"url": "https://www.hs-pforzheim.de", "name": "Hochschule Pforzheim", "state": "BW"},
    {"url": "https://www.hs-ravensburg-weingarten.de", "name": "RWU Ravensburg-Weingarten", "state": "BW"},
    {"url": "https://www.reutlingen-university.de", "name": "Hochschule Reutlingen", "state": "BW"},
    {"url": "https://www.hs-rottenburg.de", "name": "Hochschule für Forstwirtschaft Rottenburg", "state": "BW"},
    {"url": "https://www.hft-stuttgart.de", "name": "Hochschule für Technik Stuttgart", "state": "BW"},
    {"url": "https://www.hs-ulm.de", "name": "Technische Hochschule Ulm", "state": "BW"},
    {"url": "https://www.dhbw.de", "name": "Duale Hochschule Baden-Württemberg", "state": "BW"},

    # ===== BAYERN =====
    {"url": "https://www.hm.edu", "name": "Hochschule München", "state": "BY"},
    {"url": "https://www.oth-regensburg.de", "name": "OTH Regensburg", "state": "BY"},
    {"url": "https://www.th-nuernberg.de", "name": "Technische Hochschule Nürnberg", "state": "BY"},
    {"url": "https://www.th-deg.de", "name": "Technische Hochschule Deggendorf", "state": "BY"},
    {"url": "https://www.haw-landshut.de", "name": "Hochschule Landshut", "state": "BY"},
    {"url": "https://www.hs-kempten.de", "name": "Hochschule Kempten", "state": "BY"},
    {"url": "https://www.hs-coburg.de", "name": "Hochschule Coburg", "state": "BY"},
    {"url": "https://www.hs-ansbach.de", "name": "Hochschule Ansbach", "state": "BY"},
    {"url": "https://www.hs-augsburg.de", "name": "Hochschule Augsburg", "state": "BY"},
    {"url": "https://www.th-ab.de", "name": "Technische Hochschule Aschaffenburg", "state": "BY"},
    {"url": "https://www.oth-aw.de", "name": "OTH Amberg-Weiden", "state": "BY"},
    {"url": "https://www.hswt.de", "name": "Hochschule Weihenstephan-Triesdorf", "state": "BY"},
    {"url": "https://www.th-rosenheim.de", "name": "Technische Hochschule Rosenheim", "state": "BY"},
    {"url": "https://www.fhws.de", "name": "Hochschule für angewandte Wissenschaften Würzburg-Schweinfurt", "state": "BY"},
    {"url": "https://www.hs-neu-ulm.de", "name": "Hochschule Neu-Ulm", "state": "BY"},
    {"url": "https://www.th-ingolstadt.de", "name": "Technische Hochschule Ingolstadt", "state": "BY"},
    {"url": "https://www.iubh.de", "name": "IU Internationale Hochschule", "state": "BY"},

    # ===== BERLIN =====
    {"url": "https://www.htw-berlin.de", "name": "HTW Berlin", "state": "BE"},
    {"url": "https://www.bht-berlin.de", "name": "Berliner Hochschule für Technik", "state": "BE"},
    {"url": "https://www.hwr-berlin.de", "name": "HWR Berlin", "state": "BE"},
    {"url": "https://www.ash-berlin.eu", "name": "Alice Salomon Hochschule Berlin", "state": "BE"},
    {"url": "https://www.khb.hfm-berlin.de", "name": "Kunsthochschule Berlin-Weißensee", "state": "BE"},
    {"url": "https://www.hfpv-berlin.de", "name": "HfPV - Hochschule für Polizei und öffentliche Verwaltung NRW", "state": "BE"},

    # ===== BRANDENBURG =====
    {"url": "https://www.th-wildau.de", "name": "Technische Hochschule Wildau", "state": "BB"},
    {"url": "https://www.fh-potsdam.de", "name": "Fachhochschule Potsdam", "state": "BB"},
    {"url": "https://www.th-brandenburg.de", "name": "Technische Hochschule Brandenburg", "state": "BB"},
    {"url": "https://www.hnee.de", "name": "Hochschule für nachhaltige Entwicklung Eberswalde", "state": "BB"},

    # ===== BREMEN =====
    {"url": "https://www.hs-bremen.de", "name": "Hochschule Bremen", "state": "HB"},
    {"url": "https://www.hs-bremerhaven.de", "name": "Hochschule Bremerhaven", "state": "HB"},

    # ===== HAMBURG =====
    {"url": "https://www.haw-hamburg.de", "name": "HAW Hamburg", "state": "HH"},
    {"url": "https://www.fh-wedel.de", "name": "Fachhochschule Wedel", "state": "HH"},

    # ===== HESSEN =====
    {"url": "https://www.h-da.de", "name": "Hochschule Darmstadt", "state": "HE"},
    {"url": "https://www.thm.de", "name": "Technische Hochschule Mittelhessen", "state": "HE"},
    {"url": "https://www.frankfurt-university.de", "name": "Frankfurt University of Applied Sciences", "state": "HE"},
    {"url": "https://www.hs-fulda.de", "name": "Hochschule Fulda", "state": "HE"},
    {"url": "https://www.hs-rm.de", "name": "Hochschule RheinMain", "state": "HE"},

    # ===== MECKLENBURG-VORPOMMERN =====
    {"url": "https://www.hs-wismar.de", "name": "Hochschule Wismar", "state": "MV"},
    {"url": "https://www.hs-nb.de", "name": "Hochschule Neubrandenburg", "state": "MV"},
    {"url": "https://www.hs-stralsund.de", "name": "Hochschule Stralsund", "state": "MV"},

    # ===== NIEDERSACHSEN =====
    {"url": "https://www.hs-hannover.de", "name": "Hochschule Hannover", "state": "NI"},
    {"url": "https://www.ostfalia.de", "name": "Ostfalia Hochschule", "state": "NI"},
    {"url": "https://www.jade-hs.de", "name": "Jade Hochschule", "state": "NI"},
    {"url": "https://www.hs-osnabrueck.de", "name": "Hochschule Osnabrück", "state": "NI"},
    {"url": "https://www.hawk.de", "name": "HAWK Hildesheim/Holzminden/Göttingen", "state": "NI"},
    {"url": "https://www.hs-emden-leer.de", "name": "Hochschule Emden/Leer", "state": "NI"},

    # ===== NORDRHEIN-WESTFALEN =====
    {"url": "https://www.th-koeln.de", "name": "TH Köln", "state": "NW"},
    {"url": "https://www.fh-dortmund.de", "name": "Fachhochschule Dortmund", "state": "NW"},
    {"url": "https://www.fh-aachen.de", "name": "FH Aachen", "state": "NW"},
    {"url": "https://www.hs-duesseldorf.de", "name": "Hochschule Düsseldorf", "state": "NW"},
    {"url": "https://www.hs-niederrhein.de", "name": "Hochschule Niederrhein", "state": "NW"},
    {"url": "https://www.hs-bochum.de", "name": "Hochschule Bochum", "state": "NW"},
    {"url": "https://www.hs-owl.de", "name": "Technische Hochschule Ostwestfalen-Lippe", "state": "NW"},
    {"url": "https://www.w-hs.de", "name": "Westfälische Hochschule", "state": "NW"},
    {"url": "https://www.fh-bielefeld.de", "name": "FH Bielefeld", "state": "NW"},
    {"url": "https://www.hs-hamm-lippstadt.de", "name": "Hochschule Hamm-Lippstadt", "state": "NW"},
    {"url": "https://www.fh-swf.de", "name": "Fachhochschule Südwestfalen", "state": "NW"},
    {"url": "https://www.hsbi.de", "name": "Hochschule Bielefeld", "state": "NW"},
    {"url": "https://www.hs-rhein-waal.de", "name": "Hochschule Rhein-Waal", "state": "NW"},
    {"url": "https://www.hs-ruhrwest.de", "name": "Hochschule Ruhr West", "state": "NW"},

    # ===== RHEINLAND-PFALZ =====
    {"url": "https://www.hs-mainz.de", "name": "Hochschule Mainz", "state": "RP"},
    {"url": "https://www.hs-koblenz.de", "name": "Hochschule Koblenz", "state": "RP"},
    {"url": "https://www.hs-worms.de", "name": "Hochschule Worms", "state": "RP"},
    {"url": "https://www.hs-trier.de", "name": "Hochschule Trier", "state": "RP"},
    {"url": "https://www.hs-kaiserslautern.de", "name": "Hochschule Kaiserslautern", "state": "RP"},
    {"url": "https://www.hs-lu.de", "name": "Hochschule für Wirtschaft und Gesellschaft Ludwigshafen", "state": "RP"},
    {"url": "https://www.hs-bingen.de", "name": "Technische Hochschule Bingen", "state": "RP"},

    # ===== SAARLAND =====
    {"url": "https://www.htwsaar.de", "name": "htw saar", "state": "SL"},

    # ===== SACHSEN =====
    {"url": "https://www.htw-dresden.de", "name": "HTW Dresden", "state": "SN"},
    {"url": "https://www.htwk-leipzig.de", "name": "HTWK Leipzig", "state": "SN"},
    {"url": "https://www.hs-mittweida.de", "name": "Hochschule Mittweida", "state": "SN"},
    {"url": "https://www.fh-zwickau.de", "name": "Westsächsische Hochschule Zwickau", "state": "SN"},
    {"url": "https://www.hs-zittau-goerlitz.de", "name": "Hochschule Zittau/Görlitz", "state": "SN"},

    # ===== SACHSEN-ANHALT =====
    {"url": "https://www.hs-magdeburg.de", "name": "Hochschule Magdeburg-Stendal", "state": "ST"},
    {"url": "https://www.hs-harz.de", "name": "Hochschule Harz", "state": "ST"},
    {"url": "https://www.hs-merseburg.de", "name": "Hochschule Merseburg", "state": "ST"},
    {"url": "https://www.hs-anhalt.de", "name": "Hochschule Anhalt", "state": "ST"},

    # ===== SCHLESWIG-HOLSTEIN =====
    {"url": "https://www.fh-kiel.de", "name": "Fachhochschule Kiel", "state": "SH"},
    {"url": "https://www.fh-westkueste.de", "name": "Fachhochschule Westküste", "state": "SH"},
    {"url": "https://www.th-luebeck.de", "name": "Technische Hochschule Lübeck", "state": "SH"},
    {"url": "https://www.fh-flensburg.de", "name": "Hochschule Flensburg", "state": "SH"},

    # ===== THÜRINGEN =====
    {"url": "https://www.fh-erfurt.de", "name": "Fachhochschule Erfurt", "state": "TH"},
    {"url": "https://www.eah-jena.de", "name": "Ernst-Abbe-Hochschule Jena", "state": "TH"},
    {"url": "https://www.hs-schmalkalden.de", "name": "Hochschule Schmalkalden", "state": "TH"},
    {"url": "https://www.hs-nordhausen.de", "name": "Hochschule Nordhausen", "state": "TH"},
]

# =============================================================================
# PÄDAGOGISCHE HOCHSCHULEN (nur Baden-Württemberg)
# =============================================================================

PAEDAGOGISCHE_HOCHSCHULEN = [
    {"url": "https://www.ph-freiburg.de", "name": "Pädagogische Hochschule Freiburg", "state": "BW"},
    {"url": "https://www.ph-heidelberg.de", "name": "Pädagogische Hochschule Heidelberg", "state": "BW"},
    {"url": "https://www.ph-karlsruhe.de", "name": "Pädagogische Hochschule Karlsruhe", "state": "BW"},
    {"url": "https://www.ph-ludwigsburg.de", "name": "Pädagogische Hochschule Ludwigsburg", "state": "BW"},
    {"url": "https://www.ph-schwäbisch-gmünd.de", "name": "Pädagogische Hochschule Schwäbisch Gmünd", "state": "BW"},
    {"url": "https://www.ph-weingarten.de", "name": "Pädagogische Hochschule Weingarten", "state": "BW"},
]

# =============================================================================
# KUNST- UND MUSIKHOCHSCHULEN
# =============================================================================

KUNSTHOCHSCHULEN = [
    # ===== BADEN-WÜRTTEMBERG =====
    {"url": "https://www.abk-stuttgart.de", "name": "Staatliche Akademie der Bildenden Künste Stuttgart", "state": "BW"},
    {"url": "https://www.hfg-karlsruhe.de", "name": "Staatliche Hochschule für Gestaltung Karlsruhe", "state": "BW"},
    {"url": "https://www.mh-freiburg.de", "name": "Hochschule für Musik Freiburg", "state": "BW"},
    {"url": "https://www.hmdk-stuttgart.de", "name": "Hochschule für Musik und Darstellende Kunst Stuttgart", "state": "BW"},
    {"url": "https://www.hfm-karlsruhe.de", "name": "Hochschule für Musik Karlsruhe", "state": "BW"},
    {"url": "https://www.hfm-trossingen.de", "name": "Hochschule für Musik Trossingen", "state": "BW"},
    {"url": "https://www.filmakademie.de", "name": "Filmakademie Baden-Württemberg", "state": "BW"},
    {"url": "https://www.popakademie.de", "name": "Popakademie Baden-Württemberg", "state": "BW"},

    # ===== BAYERN =====
    {"url": "https://www.adbk.de", "name": "Akademie der Bildenden Künste München", "state": "BY"},
    {"url": "https://www.adbk-nuernberg.de", "name": "Akademie der Bildenden Künste Nürnberg", "state": "BY"},
    {"url": "https://www.hmtm.de", "name": "Hochschule für Musik und Theater München", "state": "BY"},
    {"url": "https://www.hfm-wuerzburg.de", "name": "Hochschule für Musik Würzburg", "state": "BY"},
    {"url": "https://www.hff-muenchen.de", "name": "Hochschule für Fernsehen und Film München", "state": "BY"},

    # ===== BERLIN =====
    {"url": "https://www.udk-berlin.de", "name": "Universität der Künste Berlin", "state": "BE"},
    {"url": "https://www.hfm-berlin.de", "name": "Hochschule für Musik Hanns Eisler Berlin", "state": "BE"},
    {"url": "https://www.dffb.de", "name": "Deutsche Film- und Fernsehakademie Berlin", "state": "BE"},

    # ===== HAMBURG =====
    {"url": "https://www.hfbk-hamburg.de", "name": "Hochschule für bildende Künste Hamburg", "state": "HH"},
    {"url": "https://www.hfmt-hamburg.de", "name": "Hochschule für Musik und Theater Hamburg", "state": "HH"},

    # ===== HESSEN =====
    {"url": "https://www.hfg-offenbach.de", "name": "Hochschule für Gestaltung Offenbach", "state": "HE"},
    {"url": "https://www.hfmdk-frankfurt.de", "name": "Hochschule für Musik und Darstellende Kunst Frankfurt", "state": "HE"},

    # ===== NORDRHEIN-WESTFALEN =====
    {"url": "https://www.kunstakademie-duesseldorf.de", "name": "Kunstakademie Düsseldorf", "state": "NW"},
    {"url": "https://www.kunstakademie-muenster.de", "name": "Kunstakademie Münster", "state": "NW"},
    {"url": "https://www.hfmt-koeln.de", "name": "Hochschule für Musik und Tanz Köln", "state": "NW"},
    {"url": "https://www.folkwang-uni.de", "name": "Folkwang Universität der Künste", "state": "NW"},
    {"url": "https://www.rsh-duesseldorf.de", "name": "Robert Schumann Hochschule Düsseldorf", "state": "NW"},
    {"url": "https://www.hfm-detmold.de", "name": "Hochschule für Musik Detmold", "state": "NW"},

    # ===== SACHSEN =====
    {"url": "https://www.hfbk-dresden.de", "name": "Hochschule für Bildende Künste Dresden", "state": "SN"},
    {"url": "https://www.hmt-leipzig.de", "name": "Hochschule für Musik und Theater Leipzig", "state": "SN"},
    {"url": "https://www.hfmdd.de", "name": "Hochschule für Musik Carl Maria von Weber Dresden", "state": "SN"},
    {"url": "https://www.palucca.eu", "name": "Palucca Hochschule für Tanz Dresden", "state": "SN"},

    # Other states
    {"url": "https://www.hfk-bremen.de", "name": "Hochschule für Künste Bremen", "state": "HB"},
    {"url": "https://www.burg-halle.de", "name": "Burg Giebichenstein Kunsthochschule Halle", "state": "ST"},
    {"url": "https://www.hmtm-hannover.de", "name": "Hochschule für Musik, Theater und Medien Hannover", "state": "NI"},
    {"url": "https://www.hfk-bremen.de", "name": "Hochschule für Künste Bremen", "state": "HB"},
    {"url": "https://www.muho-mannheim.de", "name": "Hochschule für Musik und Darstellende Kunst Mannheim", "state": "BW"},
    {"url": "https://www.hfm-saar.de", "name": "Hochschule für Musik Saar", "state": "SL"},
    {"url": "https://www.hfm-weimar.de", "name": "Hochschule für Musik Franz Liszt Weimar", "state": "TH"},
    {"url": "https://www.mh-luebeck.de", "name": "Musikhochschule Lübeck", "state": "SH"},
    {"url": "https://www.hmt-rostock.de", "name": "Hochschule für Musik und Theater Rostock", "state": "MV"},
]

# =============================================================================
# PRIVATE HOCHSCHULEN (Auswahl der wichtigsten)
# =============================================================================

PRIVATE_HOCHSCHULEN = [
    {"url": "https://www.srh.de", "name": "SRH Hochschule", "state": "BW"},
    {"url": "https://www.escp.eu", "name": "ESCP Business School Berlin", "state": "BE"},
    {"url": "https://www.hertie-school.org", "name": "Hertie School", "state": "BE"},
    {"url": "https://www.steinbeis-hochschule.de", "name": "Steinbeis Hochschule", "state": "BE"},
    {"url": "https://www.code.berlin", "name": "CODE University of Applied Sciences", "state": "BE"},
    {"url": "https://www.whu.edu", "name": "WHU – Otto Beisheim School of Management", "state": "RP"},
    {"url": "https://www.ebs.edu", "name": "EBS Universität", "state": "HE"},
    {"url": "https://www.fom.de", "name": "FOM Hochschule", "state": "NW"},
    {"url": "https://www.macromedia-fachhochschule.de", "name": "Hochschule Macromedia", "state": "BY"},
    {"url": "https://www.ism.de", "name": "International School of Management", "state": "NW"},
    {"url": "https://www.hhl.de", "name": "HHL Leipzig Graduate School of Management", "state": "SN"},
    {"url": "https://www.fs.de", "name": "Frankfurt School of Finance & Management", "state": "HE"},
    {"url": "https://www.bits-iserlohn.de", "name": "BiTS Hochschule", "state": "NW"},
    {"url": "https://www.umit.at", "name": "UMIT - Private Universität für Gesundheitswissenschaften", "state": "BY"},
    {"url": "https://www.bucerius-law-school.de", "name": "Bucerius Law School", "state": "HH"},
    {"url": "https://www.akad.de", "name": "AKAD Hochschule Stuttgart", "state": "BW"},
    {"url": "https://www.diploma.de", "name": "DIPLOMA Hochschule", "state": "HE"},
    {"url": "https://www.apollon-hochschule.de", "name": "APOLLON Hochschule", "state": "HB"},
    {"url": "https://www.euro-fh.de", "name": "Euro-FH Hamburg", "state": "HH"},
    {"url": "https://www.wings.de", "name": "WINGS Fernstudium", "state": "MV"},
]


def generate_seed(uni: dict, category: str, source_type: str, trust_boost: float) -> dict:
    """Generate a seed entry from university data."""
    return {
        "url": uni["url"],
        "name": uni["name"],
        "description": f"Deutsche Hochschule - {uni['name']}",
        "category_name": category,  # API expects category_name, not category
        "trust_boost": trust_boost,
        "source_type": source_type,
        "scope": "STATE",
        "state": uni.get("state", "")
    }


def get_all_university_seeds() -> list:
    """Get all university seeds formatted for API."""
    seeds = []

    # Universitäten - höchster Trust
    for uni in UNIVERSITAETEN:
        seeds.append(generate_seed(uni, "universities", "UNI", 0.90))

    # Fachhochschulen
    for uni in FACHHOCHSCHULEN:
        seeds.append(generate_seed(uni, "universities", "FH", 0.85))

    # Pädagogische Hochschulen - sehr relevant für Bildung
    for uni in PAEDAGOGISCHE_HOCHSCHULEN:
        seeds.append(generate_seed(uni, "universities", "PH", 0.92))

    # Kunst- und Musikhochschulen
    for uni in KUNSTHOCHSCHULEN:
        seeds.append(generate_seed(uni, "universities", "KUNST", 0.80))

    # Private Hochschulen
    for uni in PRIVATE_HOCHSCHULEN:
        seeds.append(generate_seed(uni, "universities", "PRIVATE", 0.75))

    return seeds


async def load_university_seeds():
    """Load university seeds via bulk import API."""
    seeds = get_all_university_seeds()

    print(f"Loading {len(seeds)} university seeds into {API_BASE}...")
    print(f"\nBreakdown:")
    print(f"  - Universitäten: {len(UNIVERSITAETEN)}")
    print(f"  - Fachhochschulen: {len(FACHHOCHSCHULEN)}")
    print(f"  - Pädagogische Hochschulen: {len(PAEDAGOGISCHE_HOCHSCHULEN)}")
    print(f"  - Kunst-/Musikhochschulen: {len(KUNSTHOCHSCHULEN)}")
    print(f"  - Private Hochschulen: {len(PRIVATE_HOCHSCHULEN)}")
    print(f"  - TOTAL: {len(seeds)}")

    # Count by state
    by_state = {}
    for seed in seeds:
        state = seed.get("state", "unknown")
        by_state[state] = by_state.get(state, 0) + 1
    print(f"\nBy state:")
    for state, count in sorted(by_state.items()):
        print(f"  - {state}: {count}")

    try:
        async with httpx.AsyncClient(timeout=120.0) as client:
            # Check API health first
            try:
                health_response = await client.get(f"{API_BASE}/health")
                if health_response.status_code != 200:
                    print(f"WARNING: Health check returned {health_response.status_code}")
            except httpx.ConnectError:
                print(f"ERROR: Cannot connect to API at {API_BASE}")
                print("Make sure the backend service is running:")
                print("  docker compose up -d backend")
                return False

            # Import seeds in batches to avoid timeout
            batch_size = 100
            total_imported = 0
            total_skipped = 0
            all_errors = []

            for i in range(0, len(seeds), batch_size):
                batch = seeds[i:i + batch_size]
                print(f"\nImporting batch {i // batch_size + 1} ({len(batch)} seeds)...")

                response = await client.post(
                    f"{API_BASE}/v1/edu-search/seeds/bulk-import",
                    json={"seeds": batch}
                )

                if response.status_code == 200:
                    result = response.json()
                    imported = result.get('imported', 0)
                    skipped = result.get('skipped', 0)
                    errors = result.get('errors', [])

                    total_imported += imported
                    total_skipped += skipped
                    all_errors.extend(errors)

                    print(f"  Imported: {imported}, Skipped: {skipped}")
                else:
                    print(f"  ERROR: Batch failed with status {response.status_code}")
                    try:
                        error_detail = response.json()
                        print(f"  Detail: {error_detail.get('detail', response.text[:200])}")
                    except Exception:
                        print(f"  Response: {response.text[:200]}")

            print(f"\n{'='*50}")
            print(f"TOTAL RESULTS:")
            print(f"  Imported: {total_imported}")
            print(f"  Skipped (duplicates): {total_skipped}")

            if all_errors:
                print(f"  Errors: {len(all_errors)}")
                for err in all_errors[:10]:
                    print(f"    - {err}")
                if len(all_errors) > 10:
                    print(f"    ... and {len(all_errors) - 10} more")

            # Get stats
            print("\nFetching statistics...")
            stats_response = await client.get(f"{API_BASE}/v1/edu-search/stats")
            if stats_response.status_code == 200:
                stats = stats_response.json()
                print(f"\nDatabase Statistics:")
                print(f"  Total seeds: {stats.get('total_seeds', 0)}")
                print(f"  Enabled seeds: {stats.get('enabled_seeds', 0)}")

        print("\nDone!")
        return True

    except httpx.ConnectError as e:
        print(f"\nERROR: Connection failed - {e}")
        return False
    except httpx.TimeoutException:
        print(f"\nERROR: Request timed out")
        return False
    except Exception as e:
        print(f"\nERROR: Unexpected error - {e}")
        import traceback
        traceback.print_exc()
        return False


if __name__ == "__main__":
    import sys
    print("="*60)
    print("German University Seeds Loader")
    print("="*60)
    success = asyncio.run(load_university_seeds())
    sys.exit(0 if success else 1)
