# EMTG: Evolutionary Mission Trajectory Generator
# An open-source global optimization tool for preliminary mission design
# Provided by NASA Goddard Space Flight Center
#
# Copyright (c) 2013 - 2020 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Other Rights Reserved.
#
# Licensed under the NASA Open Source License (the "License"); 
# You may not use this file except in compliance with the License. 
# You may obtain a copy of the License at:
# https://opensource.org/licenses/NASA-1.3
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
# express or implied.   See the License for the specific language
# governing permissions and limitations under the License.

def make_missionoptions_header(OptionsDefinitions, now, path = '.'):    
    with open(path + "/missionoptions.h","w") as file:

        file.write('//header file for missionoptions class\n')
        file.write('//auto-generated by make_EMTG_missionoptions_journeyoptions.py\n')
        file.write('\n')

        file.write('#pragma once\n')
        file.write('\n')
        file.write('#include "EMTG_enums.h"\n')
        file.write('#include "journeyoptions.h"\n')
        file.write('#include "file_utilities.h"\n')
        file.write('\n')
        file.write('#include <vector>\n')
        file.write('#include <string>\n')
        file.write('#include <boost/algorithm/string.hpp>\n')
        file.write('\n')
        file.write('#ifdef EMTG_OPTIONS_PYTHON_INTERFACE\n')
        file.write('#include "boost/python.hpp"\n')
        file.write('#include "boost/python/list.hpp"\n')
        file.write('#include "boost/python/extract.hpp"\n')
        file.write('#endif\n')
        file.write('\n')
        file.write('namespace EMTG\n')
        file.write('{\n')
        file.write('    class missionoptions\n')
        file.write('    {\n')
    
        file.write('    public:\n')
        file.write('        //constructor - just initializes everything\n')
        file.write('        missionoptions();\n')
        file.write('        missionoptions(std::string optionsfilename);\n')
        file.write('        \n')
        file.write('        //destructor\n')
        file.write('        ~missionoptions(){};\n')
        file.write('        \n')
        file.write('        //parser\n')
        file.write('        void parse_mission(const std::string& optionsfilename);\n')
        file.write('        void parse_line(const std::string& linestring, size_t& lineNumber);\n')
        file.write('        \n')
        file.write('        //writer\n')
        file.write('        void write(std::string optionsFileName, const bool& writeAll = true);\n')  
        file.write('        \n')
        file.write('        //initial guess assembler\n')
        file.write('        void assemble_initial_guess();\n')
        file.write('        \n')

        file.write('        //fields\n')
        file.write('        std::vector<EMTG::JourneyOptions> Journeys;//vector of journey objects\n')
        file.write('        size_t number_of_journeys;//how many journeys do we have?\n')
        file.write('        \n')

        file.write('        //fields\n')
        file.write('        size_t number_of_phases;//how many phases in this journey?\n')
        file.write('\n')
        file.write('        //internally set fields\n')
        file.write('        double G;//universal gravitation constant\n')
        file.write('        double g0;//acceleration due to gravity at sea level on Earth (m/s^2)\n')
        file.write('        double AU;//astronomical unit\n')
        file.write('        std::vector< std::tuple<std::string, double> > trialX;\n')
        file.write('        std::vector<double> current_trialX;\n')
        file.write('        double TU;\n')
        file.write('        std::string description;\n')
        file.write('        std::string outputfile;\n')
        file.write('        std::string working_directory;\n')
        file.write('\n')

        for option in OptionsDefinitions:
            file.write('        ' + option['dataType'] + ' ' + option['name'] + ';//' + option['comment'] + '\n')

        file.write('        \n')

        file.write('    private:\n')
        file.write('        //lower and upper bounds\n')
        for option in OptionsDefinitions:
            if 'std::string' not in option['dataType'] and 'bool' not in option['dataType']:
                if '[' in str(option['upperBound']) and ']' in str(option['upperBound']):#is this a string containing a list
                        file.write('        ' + option['dataType'] + ' ' + option['name'] + '_lowerBound;\n')
                        file.write('        ' + option['dataType'] + ' ' + option['name'] + '_upperBound;\n')
                else:
                        file.write('        ' + option['dataType'].replace('std::vector<','').replace('>','') + ' ' + option['name'] + '_lowerBound;\n')
                        file.write('        ' + option['dataType'].replace('std::vector<','').replace('>','') + ' ' + option['name'] + '_upperBound;\n')

        file.write('\n')

        file.write('    }; //end class missionoptions\n')
        file.write('}//close namespace EMTG\n')