# enamine_data_utils.py - script functions developed for integration with Enamine server
# Use of this code is subject to the terms of the StarDrop License Agreement and use, copying or redistribution of
# this file for use by other persons or organisations is prohibited
# Copyright(C) Optibrium Ltd 2026
# support@optibrium.com
#

def convert_json_to_data_list(molecule_data) -> list:
    data_list = []
    if 'results' in molecule_data:
        for idx, molecule in enumerate(molecule_data['results']):
            product = molecule['product']
            for weight in molecule['prices']:
                if weight == 'currency':
                    continue
                all_prices = molecule['prices'][weight]['all']
                for price in all_prices:
                    data_list.append([
                        product['smile'],  # SMILES
                        product['code'],  # Enamine ID
                        product['formula'],  # Formula
                        product['molecularWeight'],  # Molecular Weight
                        product['CAS'],  # CAS
                        product['catalog'],  # Catalogue
                        f"{price['weight']['amount']} ({price['weight']['measure']})",  # Amount in stock (g)
                        price['price']  # Price (currency)
                    ])
    return data_list
