
import clr
import sys
import os
import System
from System import AppDomain
from System.Reflection import BindingFlags

def inspect_dll(dll_path):
    print(f"Inspecting: {dll_path}")
    try:
        clr.AddReference(dll_path)
        assembly = None
        for a in AppDomain.CurrentDomain.GetAssemblies():
            if "rapiplus" in a.FullName.lower():
                assembly = a
                break
        
        if not assembly:
            print("Assembly not found.")
            return

        results = []
        # 型をすべてチェック
        for t in assembly.GetTypes():
            # Login, Logout, Alert などのキーワードを含むメソッドを持つ型を探す
            methods = []
            for m in t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static):
                name_lower = m.Name.lower()
                if "login" in name_lower or "logout" in name_lower or "alert" in name_lower:
                    kind = "[ABSTRACT] " if m.IsAbstract else ""
                    params = [f"{p.ParameterType.Name} {p.Name}" for p in m.GetParameters()]
                    methods.append(f"    {kind}{m.Name}({', '.join(params)})")
            
            if methods:
                results.append(f"\nType: {t.FullName} ({'Interface' if t.IsInterface else 'Class'})")
                results.extend(methods)

        with open("inspect_search_methods.txt", "w") as f:
            f.write("\n".join(results))
        print("Done. Results in inspect_search_methods.txt")

    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    dll_path = os.path.join(os.getcwd(), "libs", "rapiplus.dll")
    inspect_dll(dll_path)
