import requests
import numpy as np

class CommunicateUtil:
    VIEW_HOST = "192.168.1.2:7999"  #"10.7.250.52:7999" ##
    INFERENCE_HOST = "127.0.0.1"
    INFERENCE_PORT = 5000
    
    def get_view_data(init = False) -> dict:
        params = {}
        params["create_scanner"] = init
        response = requests.get(f"http://{CommunicateUtil.VIEW_HOST}/api/data", json=params)
        data = response.json()
        
        if not data["success"]:
            print(f"Failed to get view data")
            return None
        
        image_id = data["image_id"]
        depth_image = np.array(data["depth_image"], dtype=np.uint16)
        color_image = np.array(data["color_image"]).astype(np.uint8)
        depth_intrinsics = data["depth_intrinsics"]
        depth_extrinsics = np.array(data["depth_extrinsics"])
        color_intrinsics = data["color_intrinsics"]
        depth_to_color = np.array(data["depth_to_color"])
        view_data = {
            "image_id": image_id,
            "depth_image": depth_image,
            "depth_intrinsics": depth_intrinsics,
            "depth_extrinsics": depth_extrinsics,
            "color_image": color_image,
            "color_intrinsics": color_intrinsics,
            "depth_to_color": depth_to_color
        }
        return view_data
    
    def get_inference_data(view_data:dict) -> dict:
        data = {}
        return data
        
        