using System;
using System.Collections.Generic;
using Toolbox.Docking.Api.Chemical;
using Toolbox.Docking.Api.Data;
using Toolbox.Docking.Api.Objects;
using Toolbox.Docking.Api.Objects.Qsar;
using Toolbox.Docking.Api.Units;

namespace ToolboxAddinExamples.Qsar
{
    public static class QsarAddinDefinitions
    {
        public static string LogKow = "log Kow";
        public static string Log1OverMolPerLitreString = "log(1/mol/L)";

        public static List<string> AquaticToxicityEndpointLocation = new List<string>() { "Ecotoxicological Information", "Aquatic Toxicity" };

        public static Dictionary<string, string> PimephalesLc50MetaDataValues = new Dictionary<string, string>
        {
            {"Endpoint", "LC50"},
            {"Effect", "Mortality"},
            {"Test organisms (species)", "Pimephales promelas"}
        };

        public static Tuple<string, TbData> GetDurationKeyValuePair(double value, string unit)
        {
            var durationTbData = new TbData(new TbUnit(TbScale.Time.Name, unit), value);
            return new Tuple<string, TbData>("Duration", durationTbData);
        }

        public static IReadOnlyList<ChemicalWithData> GetM4TrainingSet(TbUnit log1OverMolTbUnit, TbUnit logKowTbUnit)
        {
            return new List<ChemicalWithData>
                {
                    new ChemicalWithData(108952, new [] { "phenol" }, "Oc(cccc1)c1",
                        new[] { new TbDescribedData(new TbData(logKowTbUnit, 1.46), null) },
                        new TbDescribedData(new TbData(log1OverMolTbUnit, -3.46), null)),
                    new ChemicalWithData(95578, new [] { "2-chlorophenol" }, "Oc(c(ccc1)Cl)c1",
                        new[] { new TbDescribedData(new TbData(logKowTbUnit, 2.15), null) },
                        new TbDescribedData(new TbData(log1OverMolTbUnit, -4.04), null)),
                    new ChemicalWithData(120832, new [] { "2,4-dichlorophenol" }, "Oc(c(cc(c1)Cl)Cl)c1",
                        new[] { new TbDescribedData(new TbData(logKowTbUnit, 3.06), null) },
                        new TbDescribedData(new TbData(log1OverMolTbUnit, -4.31), null)),
                    new ChemicalWithData(88062, new [] { "2,4,6-trichlorophenol" }, "Oc(c(cc(c1)Cl)Cl)c1Cl",
                        new[] { new TbDescribedData(new TbData(logKowTbUnit, 3.69), null) },
                        new TbDescribedData(new TbData(log1OverMolTbUnit, -4.41), null))
                };
        }

        public static IReadOnlyList<ChemicalWithData> GetM4TestSet(TbUnit log1OverMolTbUnit, TbUnit logKowTbUnit)
        {
            return new List<ChemicalWithData>
            {
                new ChemicalWithData(80057, new [] { "Phenol, 4,4\'-(1-methylethylidene)bis-" }, "Oc(ccc(c1)C(c(ccc(O)c2)c2)(C)C)c1",
                    new[] { new TbDescribedData(new TbData(logKowTbUnit, 3.64), null) },
                    new TbDescribedData(new TbData(log1OverMolTbUnit, -4.7), null)),
                new ChemicalWithData(135193, new [] { "2-Naphthalenol" }, "Oc(ccc(c1ccc2)c2)c1",
                    new[] { new TbDescribedData(new TbData(logKowTbUnit, 2.69), null) },
                    new TbDescribedData(new TbData(log1OverMolTbUnit, -4.62), null)),
                new ChemicalWithData(25154523, new [] { "Phenol, nonyl-" }, "Oc1ccc(cc1)CCCCCCCCC",
                    new[] { new TbDescribedData(new TbData(logKowTbUnit, 5.99), null) },
                    new TbDescribedData(new TbData(log1OverMolTbUnit, -6.24), null)),
                new ChemicalWithData(84852153, new [] { "Phenol, 4-nonyl-, branched" }, "Oc1ccc(cc1)CCC(CCC)CCC",
                    new[] { new TbDescribedData(new TbData(logKowTbUnit, 5.92), null) },
                    new TbDescribedData(new TbData(log1OverMolTbUnit, -6.24), null))
            };
        }

        public static TbQsarStatistics M4RatioModelStatistics => new TbQsarStatistics(4, 4, 4, 4);

        public static TbObjectAbout GetM4ObjectAbout()
        {
            return new TbObjectAbout
            (
                description:
                @"References:
1) Verhaar, H.J.M., Mulder, W. and Hermens, J.L.M. (1995). QSARs for ecotoxicity. In: Overview of structure-activity relationships for environmental endpoints, Part 1: General outline and procedure. Hermens, J.L.M. (Ed), Report prepared within the framework of the project ?QSAR for Prediction of Fate and Effects of Chemicals in the Environment?, an international project of the Environmenta; Technologies RTD Programme (DGXII/D-1) of the Europena Commission under contract number EV5V-CT92-0211.
2) European Economic Community (1996). Technical Guidance Document in Support of Commission Directive 93/67/EEC on Risk Assessment for New Notified Substances and Commission Regulation (EC) No 1488/94 on Risk Assessment for Existing Substances, Luxemburg: European Commission, Office for Official Publications of the European Communities.
3) Pavan M, Worth AP, Netzeva TI. 2005. Preliminary analysis of an aquatic toxicity dataset and assessment of QSAR models for narcosis. JRC Report No. 21749 EN. Accessible from: http://ecb.jrc.it/QSAR/.
            A number of publications are given though a key date is notably 1995, when the model was proposed on seemingly the same data set.
                Contact details of model developers / authors:
            The model has been redeveloped several times.The last development was done by the ECB QSAR Team.
                Dr Manuela Pavan
                European Chemicals Bureau, TP 582
            Institute for Health and Consumer Protection
            Joint Research Centre
                European Commission
            21020 Ispra(VA)
            ITALY
            E - mail: ecb.qsar@jrc.it
            Web: http://ecb.jrc.it/QSAR/
            Contact details of QRF authors:
            Dr Manuela Pavan & amp; Dr Tatiana Netzeva
                European Chemicals Bureau, TP 582
            Institute for Health and Consumer Protection
            Joint Research Centre
                European Commission
            21020 Ispra(VA)
            ITALY
            E - mail: ecb.qsar@jrc.it
            Web: http://ecb.jrc.it/QSAR/
            Model equation:
            LC50 = -2.16 - 0.723 * log Kow, log(mol / L)",
                donator: "European Chemicals Bureau (ECB)",
                disclaimer: null,
                authors: null,
                url: @"http://ecb.jrc.it/QSAR/",
                name: null,
                helpFile: null,
                additionalInfo: new[]
                {
                    new TbObjectAboutTextPair("Adopted", "Toolbox 2.0. October 2010"), 
                }
            );
        }
    }
}
