import json

def extract_service_summary(file_path, service_name):
    with open(file_path) as f:
        data = json.load(f)
    
    profiles = data["Data"]["Profiles"]
    summaries = []

    for profile in profiles:
        for account in profile["Accounts"]:
            services = account.get("Services", {})
            if service_name in services:
                summaries.append({
                    "Profile": profile["ProfileName"],
                    "AccountId": account["AccountId"],
                    "Service": service_name,
                    "Data": services[service_name]
                })
    return summaries

# Example usage
if __name__ == "__main__":
    service_name = "IAM"
    summaries = extract_service_summary("/Users/adamyasingh/Rust_Rag_v3/client-rag-rust/rag-module-rust/examples/scan_dump.json", service_name)
    with open(f"chunk_{service_name}.json", "w") as f:
        json.dump(summaries, f, indent=2)
    print(f"✅ Extracted {service_name} data saved to chunk_{service_name}.json")
