import os
import json
import numpy as np
from abc import abstractmethod, ABC

from runners.preprocessor import Preprocessor
from utils.omni_util import OmniUtil

class ObjectPosePreprocessor(Preprocessor, ABC):

    def __init__(self, config_path):
        super().__init__(config_path)
        self.load_experiment("GSNet")
        self.dataset_list_config = self.preprocess_config["dataset_list"]
        self.web_server_config = self.preprocess_config["web_server"]

    
    def run(self):
        pass
    
   
    def get_model(self, model_config):
        pass

    def get_dataloader(self, dataset_config):
        pass
    
    def preprocess(self, predicted_data):
        pass

    def prediction(self, model, dataloader):
        pass

    def save_processed_data(self, processed_data, data_config=None):
        data_path = os.path.join(str(self.experiment_path), Preprocessor.DATA, data_config["source"], data_config["data_type"])
        # ----- Debug Trace ----- #
        import ipdb; ipdb.set_trace()
        # ------------------------ #
        for frame_path in processed_data:
            data_item = processed_data[frame_path]
            scene = os.path.basename(os.path.dirname(frame_path))
            idx = os.path.basename(frame_path)
            target_scene_path = os.path.join(str(data_path), scene) 
            if not os.path.exists(target_scene_path):
                os.makedirs(target_scene_path)
            label_save_path = os.path.join(
                target_scene_path,OmniUtil.SCORE_LABEL_TEMPLATE.format(idx)
            )
            with open(label_save_path, "w+") as f:
                json.dump(data_item, f)
        print("Processed data saved to: ", data_path)
