import os
import glob

class Load_Data_Prepare:
    def __init__(self) -> None:
        self.__Label_List = []
        self.__Data_List = []
        self.__Contect_Dictionary = {}
        self.__Final_Dict_data = {}
        self.__PreSave_Data_Root = [] # 所有要讀取資料所在的位置
        self.__Data_Content = []
        pass

    def Set_Data_Content(self, Content, Length):
        tmp = []
        for i in range(Length):
            tmp.append(Content)

        self.__Data_Content = tmp

    def Set_Label_List(self, Label_List): # 為讀取檔案準備label list
        self.__Label_List = Label_List
        pass

    def Set_Data_List(self, Data_List):
        self.__Data_List = Data_List
        pass

    def Set_Data_Dictionary(self, Label : list, Content : list, Total_Label_Size : int):
        '''將資料合併成1個Dict'''
        for i in range(Total_Label_Size):
            temp = {Label[i] : Content[i]}
            self.__Contect_Dictionary.update(temp)
        pass

    def Set_Final_Dict_Data(self, Name : list, Label_Root : list, Label_LabelEncoding : list, Label_Len : int):
        '''
        Name : 讀取出來的Data Root的名字
        Label_Root: 所有影像資料的路徑
        Label_LabelEncoding: LabelEncoding後的資料
        Label_Len: Label的大小
        '''
        for i in range(Label_Len):
            temp = {Name[i] + "_Data_Root" : Label_Root[Name[i]]}
            self.__Final_Dict_data.update(temp)

        for i in range(Label_Len):
            temp = {Name[i] + "_Data_LabelEncoding" : Label_LabelEncoding[i]}
            self.__Final_Dict_data.update(temp)

    def Set_PreSave_Data_Root(self, PreSave_Roots : list):
        for Root in PreSave_Roots:
            self.__PreSave_Data_Root.append(Root)

    def Get_Label_List(self): 
        ''' 
        將private的資料讀取出來
        現在要放入需要的Label 需要先Set Label
        '''
        return self.__Label_List
    
    def Get_Data_List(self):
        return self.__Data_List
    
    def Get_Data_Dict(self):
        return self.__Contect_Dictionary
    
    def Get_Final_Data_Dict(self):
        return self.__Final_Dict_data
    
    def Get_PreSave_Data_Root(self):
        return self.__PreSave_Data_Root
    
    def Get_Data_Content(self):
        return self.__Data_Content

class Load_Data_Tools():
    def __init__(self) -> None:
        pass

    def get_data_root(self, root, data_dict, classify_label, judge = True) -> dict :
        '''取得資料路徑'''
        for label in classify_label:
            if judge:
                path = os.path.join(root, label, "*")
            else:
                path = os.path.join(root, "*")
            path = glob.glob(path)
            data_dict[label] = path
        return data_dict