"""Here to put the data loading of XARRAYS from OCean Model"""
import os
import pandas as pd
import time
import xarray as xr

#def __init__(file_paths):
        #file_paths = file_paths
        #self.result_table = pd.DataFrame(columns=['File Name', 'Depth Variable Present', 'Depth Variable Dimensions'])


def list_data(file_paths):

    print("The main directory to access the files....")
    print(file_paths)
    return os.listdir(file_paths)
def list_files(file_paths):
  file_list = [os.listdir(file_paths)]
  print("file_list: ",file_list)
  return file_list

def list_directories(file_paths):
    full_path = os.path.abspath(file_paths)
    print("Full Path:", full_path)

    try:

        directory_list = os.listdir(file_paths)
        print("Directories:", directory_list)
    except Exception as e:
        print("Error:", e)

    return directory_list




def loadx_variable(path, variables, check_variable,version):
    start_time_load = time.time()

    # Define a dictionary to store the loaded datasets
    datasets = {}

    # List of expected variable names
    list_multivar = check_variable # ['INTPP', 'NO3', 'PO4', 'SI', 'THETAO', 'MLOTST', 'DFE', 'ZMESOOS', 'ZMICROOS', 'RSNTDS']
    print("list_multivar load:", list_multivar)

    # Iterate over each variable to check if it needs to be loaded
    for var in variables:
        var_upper = var.upper()
        if var_upper in list_multivar:
            files = os.path.join(path, var, "gn", version, '*gn_*.nc')
            print(f"Loading variable {var_upper} from directory: {files}")
            datasets[var_upper] = xr.open_mfdataset(files, combine='by_coords')

    end_time_load = time.time()
    time_used_load = end_time_load - start_time_load

    #print("datasets", datasets)
    print(f"Time used for entire LOAD: {time_used_load:.4f} Seconds")
    print(f"Time used for entire LOAD: {time_used_load/60:.4f} Minutes")
    print(f"Time used for entire LOAD: {time_used_load/3600:.4f} Hours")

    return datasets

