//! Example usage of the AWS Estate Service
//! 
//! This example demonstrates how to use the new AWS Estate Service 
//! integrated into the RAG module for parsing AWS cloud infrastructure data.

use serde_json::json;
use rag_module::RagModule;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Initialize the RAG module
    let rag = RagModule::new("./test_data").await?;
    rag.initialize().await?;
    
    println!("RAG Module initialized with AWS Estate Service");
    
    // Example AWS estate data
    let aws_estate_data = json!([
        {
    "account_id": "288761761556",
    "role_arn": null,
    "account_name": "",
    "scan_timestamp": null,
    "services": {
      "ec2": {
        "instances": [
          {
            "instance_id": "i-08619fa3385e63bab",
            "instance_type": "c4.large",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-08-26T12:37:51+00:00",
            "name": "escher-scan-stream-v2"
          },
          {
            "instance_id": "i-0f6ce804a1a464e1d",
            "instance_type": "c4.large",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-08-23T06:45:12+00:00",
            "name": "slack-ec2-stream"
          },
          {
            "instance_id": "i-01697357246074533",
            "instance_type": "t2.micro",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-09-05T07:06:47+00:00",
            "name": "space-argo-dev-inst-1"
          },
          {
            "instance_id": "i-0b1e8b61d9b846a3e",
            "instance_type": "t2.micro",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-07-21T04:22:19+00:00",
            "name": "escher-ec2"
          },
          {
            "instance_id": "i-0a5ff673a52c7a1c7",
            "instance_type": "c4.large",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-07-28T05:05:24+00:00",
            "name": "escher-stream-ec2"
          },
          {
            "instance_id": "i-06a446d8aaec15d27",
            "instance_type": "c4.large",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-08-29T04:11:05+00:00",
            "name": "finops-ec2-stream"
          },
          {
            "instance_id": "i-07901ab76d1aca487",
            "instance_type": "c1.xlarge",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-09-29T10:42:10+00:00",
            "name": "dev-benchmark"
          }
        ],
        "volumes_count": 13,
        "elastic_ips_total": 7,
        "elastic_ips_attached": 3,
        "elastic_ips_unattached": 4,
        "elastic_ips_instance_attached": 0,
        "elastic_ips_eni_attached": 3,
        "vpcs_count": 7,
        "permissions": {
          "service_info": {
            "display_name": "EC2 Compute",
            "icon": "🖥️",
            "category": "compute",
            "description": "Amazon Elastic Compute Cloud"
          },
          "actions": {
            "permission_level": "Full",
            "create": {
              "allowed": true,
              "display_name": "Create",
              "risk_level": "medium",
              "aws_actions": [
                "ec2:RunInstances",
                "ec2:CreateTags",
                "ec2:CreateSecurityGroup"
              ],
              "conditions": null
            },
            "start": {
              "allowed": true,
              "display_name": "Start",
              "risk_level": "low",
              "aws_actions": [
                "ec2:StartInstances"
              ],
              "conditions": null
            },
            "stop": {
              "allowed": true,
              "display_name": "Stop",
              "risk_level": "low",
              "aws_actions": [
                "ec2:StopInstances"
              ],
              "conditions": null
            },
            "terminate": {
              "allowed": true,
              "display_name": "Terminate",
              "risk_level": "high",
              "aws_actions": [
                "ec2:TerminateInstances"
              ],
              "conditions": null
            },
            "read": {
              "allowed": true,
              "display_name": "Read",
              "risk_level": "low",
              "aws_actions": [
                "ec2:DescribeInstances",
                "ec2:DescribeInstanceStatus"
              ],
              "conditions": null
            }
          }
        }
      },
      "ebs": {
        "total_volumes": 13,
        "attached_volumes": 8,
        "unattached_volumes": 5,
        "recently_detached": 0,
        "long_term_unused": 5,
        "total_size_gb": 1425,
        "attached_size_gb": 949,
        "unattached_size_gb": 476,
        "long_term_unused_size_gb": 476,
        "volume_types": {
          "gp2": {
            "count": 7,
            "unattached": 3
          },
          "gp3": {
            "count": 6,
            "unattached": 2
          }
        },
        "regions_with_unused": [
          "us-east-1"
        ],
        "region_unused_counts": {
          "us-east-1": 5
        }
      },
      "rds": {
        "instances": [
          {
            "instance_id": "db-VXDRDM3CQ6OIKGF7HLGVPPO454",
            "db_instance_identifier": "dev-eshop-mysql-rds",
            "db_instance_class": "db.t3.micro",
            "engine": "mysql",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "dev-eshop-mysql-rds",
            "replication_role": "Instance",
            "replication_source": null
          },
          {
            "instance_id": "db-2XYHZFX3PDXT3CD3LGIK435ALY",
            "db_instance_identifier": "dev-tesserade-pg-rds",
            "db_instance_class": "db.m5.xlarge",
            "engine": "postgres",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "dev-tesserade-pg-rds",
            "replication_role": "Instance",
            "replication_source": null
          },
          {
            "instance_id": "db-QTKHKSX6HCJBUAIZSSTOLAHQMY",
            "db_instance_identifier": "mysql-test-instance1",
            "db_instance_class": "db.t3.micro",
            "engine": "mysql",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "mysql-test-instance1",
            "replication_role": "Instance",
            "replication_source": null
          },
          {
            "instance_id": "db-AO7N2SOEFDAE2NN4VBLPDRKGHM",
            "db_instance_identifier": "pg-instance-main1",
            "db_instance_class": "db.t3.small",
            "engine": "postgres",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "pg-instance-main1",
            "replication_role": "Instance",
            "replication_source": null
          },
          {
            "instance_id": "db-ZM5OP7TCL4CTFCJ67SL5ORIDPQ",
            "db_instance_identifier": "pg-instance-main2",
            "db_instance_class": "db.t4g.medium",
            "engine": "postgres",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "pg-instance-main2",
            "replication_role": "Instance",
            "replication_source": null
          },
          {
            "instance_id": "db-QUIUOU5G7GDUMLPJRSPRID4UYU",
            "db_instance_identifier": "prod-ecomm-mysql-rds-instance-1",
            "db_instance_class": "db.r5.xlarge",
            "engine": "aurora-mysql",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "prod-ecomm-mysql-rds-instance-1",
            "replication_role": "Instance",
            "replication_source": null
          },
          {
            "instance_id": "db-2FJQN5PFCZJSGY3DGLP3QAFDAA",
            "db_instance_identifier": "prod-tesserade-trademan-pg-rds",
            "db_instance_class": "db.t3.micro",
            "engine": "postgres",
            "db_instance_status": "available",
            "region": "us-east-1",
            "name": "prod-tesserade-trademan-pg-rds",
            "replication_role": "Instance",
            "replication_source": null
          }
        ],
        "clusters_count": 1,
        "snapshots_count": 31,
        "permissions": {
          "service_info": {
            "display_name": "RDS Database",
            "icon": "🗄️",
            "category": "database",
            "description": "Amazon Relational Database Service"
          },
          "actions": {
            "permission_level": "Full",
            "create": {
              "allowed": true,
              "display_name": "Create",
              "risk_level": "medium",
              "aws_actions": [
                "rds:CreateDBInstance",
                "rds:CreateDBCluster"
              ],
              "conditions": null
            },
            "read": {
              "allowed": true,
              "display_name": "Read",
              "risk_level": "low",
              "aws_actions": [
                "rds:DescribeDBInstances",
                "rds:DescribeDBClusters"
              ],
              "conditions": null
            },
            "modify": {
              "allowed": true,
              "display_name": "Modify",
              "risk_level": "medium",
              "aws_actions": [
                "rds:ModifyDBInstance",
                "rds:ModifyDBCluster"
              ],
              "conditions": null
            },
            "delete": {
              "allowed": true,
              "display_name": "Delete",
              "risk_level": "high",
              "aws_actions": [
                "rds:DeleteDBInstance",
                "rds:DeleteDBCluster"
              ],
              "conditions": null
            }
          }
        }
      },
      "s3": {
        "total_buckets": 23,
        "public_buckets": 0,
        "bucket_names": [
          "escher-bucket-test-dev (us-east-1)",
          "escher-dev-test (us-east-1)",
          "test-escher-prod (us-east-1)",
          "test-escher (us-east-1)",
          "rag-client-backup-20250925-224157 (us-east-1)",
          "escher-dev-cf-templates-1758030103 (ap-south-1)",
          "escher-updates-frontend-dev (ap-southeast-1)",
          "escher-app-updates (ap-southeast-1)",
          "escher-test (us-east-1)",
          "aws-sam-cli-managed-default-samclisourcebucket-psntlsjjdvyv (ap-south-2)",
          "escher-dev-cf-templates-1756985923 (ap-south-1)",
          "aws-sam-cli-managed-default-samclisourcebucket-9wpmsdrbseyf (ap-south-1)",
          "aws-sam-cli-managed-default-samclisourcebucket-4wkburapvnib (us-west-2)",
          "test-bucket-cada367e-0484-4967-b820-27b24a9a8390 (us-east-1)",
          "test-bucket-5f562756-9661-4a54-ab9d-718afd1857e7 (us-east-1)",
          "test-bucket-bb401105-5ede-427f-bb34-6d46cfba0ddf (us-east-1)",
          "stackset-escher-app-infra-pipelinebuiltartifactbuc-hustcpjpo3rz (us-west-1)",
          "stackset-escher-app-infra-pipelinebuiltartifactbuc-encqypul4oqc (us-west-1)",
          "cdc-data-pg-instance-main2 (us-east-1)",
          "aws-sam-cli-managed-default-samclisourcebucket-3mhsgjvm6ikb (us-east-1)"
        ],
        "latest_buckets_info": [
          {
            "name": "escher-bucket-test-dev",
            "s3_identifier": "escher-bucket-test-dev",
            "creation_date": "2025-10-03T05:05:37+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "escher-dev-test",
            "s3_identifier": "escher-dev-test",
            "creation_date": "2025-10-01T13:46:57+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "test-escher-prod",
            "s3_identifier": "test-escher-prod",
            "creation_date": "2025-10-01T08:44:14+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "test-escher",
            "s3_identifier": "test-escher",
            "creation_date": "2025-09-30T13:20:59+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "rag-client-backup-20250925-224157",
            "s3_identifier": "rag-client-backup-20250925-224157",
            "creation_date": "2025-09-25T17:12:00+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "escher-dev-cf-templates-1758030103",
            "s3_identifier": "escher-dev-cf-templates-1758030103",
            "creation_date": "2025-09-16T13:41:58+00:00",
            "region": "ap-south-1",
            "is_public": false
          },
          {
            "name": "escher-updates-frontend-dev",
            "s3_identifier": "escher-updates-frontend-dev",
            "creation_date": "2025-09-15T09:31:14+00:00",
            "region": "ap-southeast-1",
            "is_public": false
          },
          {
            "name": "escher-app-updates",
            "s3_identifier": "escher-app-updates",
            "creation_date": "2025-09-12T09:43:41+00:00",
            "region": "ap-southeast-1",
            "is_public": false
          },
          {
            "name": "escher-test",
            "s3_identifier": "escher-test",
            "creation_date": "2025-09-12T07:19:20+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "aws-sam-cli-managed-default-samclisourcebucket-psntlsjjdvyv",
            "s3_identifier": "aws-sam-cli-managed-default-samclisourcebucket-psntlsjjdvyv",
            "creation_date": "2025-09-06T09:23:18+00:00",
            "region": "ap-south-2",
            "is_public": false
          },
          {
            "name": "escher-dev-cf-templates-1756985923",
            "s3_identifier": "escher-dev-cf-templates-1756985923",
            "creation_date": "2025-09-04T11:38:44+00:00",
            "region": "ap-south-1",
            "is_public": false
          },
          {
            "name": "aws-sam-cli-managed-default-samclisourcebucket-9wpmsdrbseyf",
            "s3_identifier": "aws-sam-cli-managed-default-samclisourcebucket-9wpmsdrbseyf",
            "creation_date": "2025-08-06T03:24:39+00:00",
            "region": "ap-south-1",
            "is_public": false
          },
          {
            "name": "aws-sam-cli-managed-default-samclisourcebucket-4wkburapvnib",
            "s3_identifier": "aws-sam-cli-managed-default-samclisourcebucket-4wkburapvnib",
            "creation_date": "2025-08-06T03:22:33+00:00",
            "region": "us-west-2",
            "is_public": false
          },
          {
            "name": "test-bucket-cada367e-0484-4967-b820-27b24a9a8390",
            "s3_identifier": "test-bucket-cada367e-0484-4967-b820-27b24a9a8390",
            "creation_date": "2025-07-30T09:14:40+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "test-bucket-5f562756-9661-4a54-ab9d-718afd1857e7",
            "s3_identifier": "test-bucket-5f562756-9661-4a54-ab9d-718afd1857e7",
            "creation_date": "2025-07-30T09:09:28+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "test-bucket-bb401105-5ede-427f-bb34-6d46cfba0ddf",
            "s3_identifier": "test-bucket-bb401105-5ede-427f-bb34-6d46cfba0ddf",
            "creation_date": "2025-07-30T06:45:21+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "stackset-escher-app-infra-pipelinebuiltartifactbuc-hustcpjpo3rz",
            "s3_identifier": "stackset-escher-app-infra-pipelinebuiltartifactbuc-hustcpjpo3rz",
            "creation_date": "2025-07-16T13:02:42+00:00",
            "region": "us-west-1",
            "is_public": false
          },
          {
            "name": "stackset-escher-app-infra-pipelinebuiltartifactbuc-encqypul4oqc",
            "s3_identifier": "stackset-escher-app-infra-pipelinebuiltartifactbuc-encqypul4oqc",
            "creation_date": "2025-06-14T13:03:10+00:00",
            "region": "us-west-1",
            "is_public": false
          },
          {
            "name": "cdc-data-pg-instance-main2",
            "s3_identifier": "cdc-data-pg-instance-main2",
            "creation_date": "2025-06-11T06:33:06+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "aws-sam-cli-managed-default-samclisourcebucket-3mhsgjvm6ikb",
            "s3_identifier": "aws-sam-cli-managed-default-samclisourcebucket-3mhsgjvm6ikb",
            "creation_date": "2025-05-17T00:55:51+00:00",
            "region": "us-east-1",
            "is_public": false
          }
        ],
        "showing_latest": 20,
        "permissions": {
          "service_info": {
            "display_name": "S3 Storage",
            "icon": "📁",
            "category": "storage",
            "description": "Amazon Simple Storage Service"
          },
          "actions": {
            "permission_level": "Full",
            "read": {
              "allowed": true,
              "display_name": "Read",
              "risk_level": "low",
              "aws_actions": [
                "s3:GetObject",
                "s3:ListBucket",
                "s3:GetObjectVersion"
              ],
              "conditions": null
            },
            "write": {
              "allowed": true,
              "display_name": "Write",
              "risk_level": "medium",
              "aws_actions": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:CreateBucket"
              ],
              "conditions": null
            },
            "delete": {
              "allowed": true,
              "display_name": "Delete",
              "risk_level": "high",
              "aws_actions": [
                "s3:DeleteObject",
                "s3:DeleteBucket",
                "s3:DeleteObjectVersion"
              ],
              "conditions": null
            }
          }
        }
      },
      "lambda": {
        "functions": [
          {
            "name": "eShopping_User_Simulator",
            "lambda_identifier": "eShopping_User_Simulator",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-07-10T13:44:39.000+0000"
          },
          {
            "name": "Tessarade-Dividend-Simulation",
            "lambda_identifier": "Tessarade-Dividend-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-07-18T16:35:14.000+0000"
          },
          {
            "name": "aws-rds-pg-alert-to-slack",
            "lambda_identifier": "aws-rds-pg-alert-to-slack",
            "runtime": "python3.11",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-08-05T08:05:46.000+0000"
          },
          {
            "name": "EscherGoService",
            "lambda_identifier": "EscherGoService",
            "runtime": "provided.al2",
            "memory_size": 128,
            "timeout": 120,
            "region": "us-east-1",
            "last_modified": "2025-06-19T10:54:30.000+0000"
          },
          {
            "name": "Tessarade-WatchList-Simulation",
            "lambda_identifier": "Tessarade-WatchList-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-07-18T17:18:58.000+0000"
          },
          {
            "name": "web-service-lambda",
            "lambda_identifier": "web-service-lambda",
            "runtime": "provided.al2023",
            "memory_size": 512,
            "timeout": 30,
            "region": "us-east-1",
            "last_modified": "2025-05-16T14:21:38.000+0000"
          },
          {
            "name": "CDC-reader",
            "lambda_identifier": "CDC-reader",
            "runtime": "provided.al2023",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-05-29T08:51:29.000+0000"
          },
          {
            "name": "prod-escher-storage-service",
            "lambda_identifier": "prod-escher-storage-service",
            "runtime": "provided.al2",
            "memory_size": 256,
            "timeout": 30,
            "region": "us-east-1",
            "last_modified": "2025-09-25T11:56:59.000+0000"
          },
          {
            "name": "aws-rds-pg-alerts-to-slack",
            "lambda_identifier": "aws-rds-pg-alerts-to-slack",
            "runtime": "python3.11",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-10-02T07:11:41.000+0000"
          },
          {
            "name": "Tessarade-Company-Simulation",
            "lambda_identifier": "Tessarade-Company-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 30,
            "region": "us-east-1",
            "last_modified": "2025-09-18T09:02:13.000+0000"
          },
          {
            "name": "Tessarade-Trades-Simulation",
            "lambda_identifier": "Tessarade-Trades-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 30,
            "region": "us-east-1",
            "last_modified": "2025-09-18T09:04:56.000+0000"
          },
          {
            "name": "Tessarade-Investors-Simulation",
            "lambda_identifier": "Tessarade-Investors-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 30,
            "region": "us-east-1",
            "last_modified": "2025-09-18T09:10:06.000+0000"
          },
          {
            "name": "postgres-cdc-function",
            "lambda_identifier": "postgres-cdc-function",
            "runtime": "provided.al2",
            "memory_size": 512,
            "timeout": 480,
            "region": "us-east-1",
            "last_modified": "2025-05-22T05:58:42.000+0000"
          },
          {
            "name": "Tessarade-WatchList-Items-Simulation",
            "lambda_identifier": "Tessarade-WatchList-Items-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 3,
            "region": "us-east-1",
            "last_modified": "2025-07-18T17:32:18.000+0000"
          },
          {
            "name": "Tessarade-Wallet-Simulation",
            "lambda_identifier": "Tessarade-Wallet-Simulation",
            "runtime": "python3.13",
            "memory_size": 128,
            "timeout": 30,
            "region": "us-east-1",
            "last_modified": "2025-09-18T09:03:38.000+0000"
          }
        ]
      },
      "vpcs": {
        "total_vpcs": 7,
        "default_vpcs": 4,
        "total_subnets": 28,
        "public_subnets": 22,
        "private_subnets": 6,
        "vpc_regions": [
          "us-east-1",
          "ap-south-2",
          "ap-south-1",
          "us-west-2"
        ],
        "internet_gateways_count": 7,
        "total_eips_in_vpcs": 0,
        "attached_eips_in_vpcs": 0,
        "unattached_eips_total": 4
      }
    }
  },
  {
    "account_id": "547639878546",
    "role_arn": "arn:aws:iam::547639878546:role/escher_cross_role",
    "account_name": "",
    "scan_timestamp": null,
    "services": {
      "ec2": {
        "instances": [
          {
            "instance_id": "i-0f9f85890fc371f78",
            "instance_type": "t2.micro",
            "state": "running",
            "region": "us-east-1",
            "launch_time": "2025-08-22T18:19:11+00:00",
            "name": "i-0f9f85890fc371f78"
          }
        ],
        "volumes_count": 1,
        "elastic_ips_total": 3,
        "elastic_ips_attached": 0,
        "elastic_ips_unattached": 3,
        "elastic_ips_instance_attached": 0,
        "elastic_ips_eni_attached": 0,
        "vpcs_count": 1,
        "permissions": {
          "service_info": {
            "display_name": "EC2 Compute",
            "icon": "🖥️",
            "category": "compute",
            "description": "Amazon Elastic Compute Cloud"
          },
          "actions": {
            "permission_level": "Full",
            "create": {
              "allowed": true,
              "display_name": "Create",
              "risk_level": "medium",
              "aws_actions": [
                "ec2:RunInstances",
                "ec2:CreateTags",
                "ec2:CreateSecurityGroup"
              ],
              "conditions": null
            },
            "start": {
              "allowed": true,
              "display_name": "Start",
              "risk_level": "low",
              "aws_actions": [
                "ec2:StartInstances"
              ],
              "conditions": null
            },
            "stop": {
              "allowed": true,
              "display_name": "Stop",
              "risk_level": "low",
              "aws_actions": [
                "ec2:StopInstances"
              ],
              "conditions": null
            },
            "terminate": {
              "allowed": true,
              "display_name": "Terminate",
              "risk_level": "high",
              "aws_actions": [
                "ec2:TerminateInstances"
              ],
              "conditions": null
            },
            "read": {
              "allowed": true,
              "display_name": "Read",
              "risk_level": "low",
              "aws_actions": [
                "ec2:DescribeInstances",
                "ec2:DescribeInstanceStatus"
              ],
              "conditions": null
            }
          }
        }
      },
      "ebs": {
        "total_volumes": 1,
        "attached_volumes": 1,
        "unattached_volumes": 0,
        "recently_detached": 0,
        "long_term_unused": 0,
        "total_size_gb": 8,
        "attached_size_gb": 8,
        "unattached_size_gb": 0,
        "long_term_unused_size_gb": 0,
        "volume_types": {
          "gp2": {
            "count": 1,
            "unattached": 0
          }
        },
        "regions_with_unused": [],
        "region_unused_counts": {}
      },
      "s3": {
        "total_buckets": 2,
        "public_buckets": 0,
        "bucket_names": [
          "aparna-dev-test (us-east-1)",
          "tex-instru-test-bckt (us-east-1)"
        ],
        "latest_buckets_info": [
          {
            "name": "aparna-dev-test",
            "s3_identifier": "aparna-dev-test",
            "creation_date": "2025-10-03T07:16:28+00:00",
            "region": "us-east-1",
            "is_public": false
          },
          {
            "name": "tex-instru-test-bckt",
            "s3_identifier": "tex-instru-test-bckt",
            "creation_date": "2025-07-24T04:50:07+00:00",
            "region": "us-east-1",
            "is_public": false
          }
        ],
        "showing_latest": 2,
        "permissions": {
          "service_info": {
            "display_name": "S3 Storage",
            "icon": "📁",
            "category": "storage",
            "description": "Amazon Simple Storage Service"
          },
          "actions": {
            "permission_level": "Full",
            "read": {
              "allowed": true,
              "display_name": "Read",
              "risk_level": "low",
              "aws_actions": [
                "s3:GetObject",
                "s3:ListBucket",
                "s3:GetObjectVersion"
              ],
              "conditions": null
            },
            "write": {
              "allowed": true,
              "display_name": "Write",
              "risk_level": "medium",
              "aws_actions": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:CreateBucket"
              ],
              "conditions": null
            },
            "delete": {
              "allowed": true,
              "display_name": "Delete",
              "risk_level": "high",
              "aws_actions": [
                "s3:DeleteObject",
                "s3:DeleteBucket",
                "s3:DeleteObjectVersion"
              ],
              "conditions": null
            }
          }
        }
      },
      "vpcs": {
        "total_vpcs": 1,
        "default_vpcs": 1,
        "total_subnets": 6,
        "public_subnets": 6,
        "private_subnets": 0,
        "vpc_regions": [
          "us-east-1"
        ],
        "internet_gateways_count": 1,
        "total_eips_in_vpcs": 0,
        "attached_eips_in_vpcs": 0,
        "unattached_eips_total": 3
      }
    }
  }
    ]);
    
    // Ingest the AWS estate data using the new service with user context
    println!("Ingesting AWS estate data...");
    let result = rag.ingest_aws_estate(aws_estate_data, "user123").await?;
    
    println!("AWS Estate Ingestion Results:");
    println!("  Total accounts processed: {}", result.total_accounts);
    println!("  Total services processed: {}", result.total_services);
    println!("  Total resources found: {}", result.total_resources);
    println!("  Resources successfully parsed: {}", result.parsed_resources);
    println!("  Resources failed to parse: {}", result.failed_resources);
    println!("  Supported services: {:?}", result.supported_services);
    println!("  Unsupported services: {:?}", result.unsupported_services);
    println!("  Documents created: {}", result.create_result.created);
    println!("  Failed document creations: {:?}", result.create_result.failed);
    
    // Search for AWS resources
    println!("\nSearching for EC2 instances...");
    let search_options = rag_module::SearchOptions {
        limit: Some(10),
        score_threshold: Some(0.0),
        filter: None,
        collection_name: None,
        privacy_level: None,
        with_payload: Some(true),
    };
    
    let search_results = rag.search("aws_estate", "EC2 instance running", "user123", search_options).await?;
    println!("Found {} search results", search_results.len());
    
    for result in search_results.iter().take(3) {
        println!("  - ID: {}, Score: {:.3}", result.id, result.score);
        if let Some(ref payload) = result.payload {
            if let Some(account_id) = payload.get("account_id") {
                println!("    Account: {}", account_id);
            }
            if let Some(service) = payload.get("service") {
                println!("    Service: {}", service);
            }
        }
    }
    
    println!("\nAWS Estate Service integration completed successfully!");
    Ok(())
}