/*
 * Copyright (c) 2026 University of Insubria <https://www.uninsubria.it>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version. All we ask is that proper credit is given
 * for our work, which includes - but is not limited to - adding the above
 * copyright notice to the beginning of your source code files, and to any
 * copyright notice that you may distribute with programs based on this work.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.
 * <https://fsf.org/>
 */

package qsardes.cdk;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.qsar.IMolecularDescriptor;

/**
 * This class provides tools to get and organize data from CDK descriptor
 * classes.
 *
 * @author Nicola Chirico
 */
public final class CdkTools
{
    /**
     * Constructs the CDK tools class.
     *
     */
    public CdkTools()
    {
    }

    /**
     * Gets CDK descriptor empty map.
     *
     * @param descr CDK descriptor class.
     *
     * @return Descriptor no-values mapped as name:NaN.
     */
    public Map<String, String> get_empty_map(IMolecularDescriptor descr)
    {
        Map<String, String> map = new LinkedHashMap<>();

        for (String name : descr.getDescriptorNames()) {
            map.put(name, String.valueOf(Double.NaN));
        }

        return map;
    }

    /**
     * Gets CDK descriptor names.
     *
     * @param descr CDK descriptor class.
     *
     * @return Descriptor names.
     */
    public List<String> get_descriptor_names(IMolecularDescriptor descr)
    {
        return Arrays.asList(descr.getDescriptorNames());
    }

    /**
     * Gets CDK descriptor names.
     *
     * @param descr CDK descriptor class.
     * @param params CDK descriptor parameters.
     *
     * @return Descriptor names.
     */
    public List<String> get_descriptor_names(IMolecularDescriptor descr,
            Object[] params)
    {
        try {
            descr.setParameters(params);
        } catch (CDKException ex) {
            System.err.println(ex);
        }

        return Arrays.asList(descr.getDescriptorNames());
    }
}
