"""
Example translation system

Copyright (C) 2023 NIBIO <http://www.nibio.no/>. 

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program 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 Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""

import unittest

import json

from src.vips_reference_model.reference_model import *
from vipscore_common.entities import *

def get_model_configuration():
    with open ("tests/weather_data_2015_NO_aas_TMD.json") as f:
        weather_observations = json.load(f)
        return ModelConfiguration(
            model_id=ReferenceModel.MODEL_ID,
            config_parameters={
                "sowingDate": "2022-03-01",
                "timeZone" : "Europe/Oslo",
                "observations": weather_observations
            }
        )

class TestReferenceModel(unittest.TestCase):
    def test_set_configuration(self):
        """
        Passing a configuration object does not fail
        """
        #print(get_model_configuration())
        instance = ReferenceModel()
        mc=get_model_configuration()
        #print(mc.json())
        instance.set_configuration(mc)

    def test_get_result(self):
        """
        We get a series of results from the calculation,
        and the TMDD is as expected
        """
        instance = ReferenceModel()
        instance.set_configuration(get_model_configuration())
        result_list = instance.get_result()
        self.assertIsNotNone(result_list)
        last_result = result_list[len(result_list)-1]
        self.assertIsNotNone(result_list[0].valid_time_start)
        self.assertEqual(555.8507083333333, last_result.get_value("WEATHER","TMDD"))

    def test_get_model_id(self):
         """
         The model returns the correct ID
         """
         instance = ReferenceModel()
         self.assertEqual(instance.model_id, ReferenceModel.MODEL_ID)
        
    def test_get_license(self):
        """
        The model returns its license
        """
        instance = ReferenceModel()
        self.assertIsNotNone(instance.license)

    def test_get_copyright(self):
        """
        The model returns its copyright notice
        """
        instance = ReferenceModel()
        self.assertEqual(instance.copyright, ReferenceModel.COPYRIGHT)
    
    def test_get_sample_config(self):
        """
        The model returns its sample configuration
        """
        instance = ReferenceModel()
        self.assertIsNotNone(instance.sample_config)
    
    def test_get_model_name(self):
        """
        The model returns its name in the default language
        """
        instance = ReferenceModel()
        self.assertEqual(instance.get_model_name(), "Reference Model")
        # Norwegian
        self.assertEqual(instance.get_model_name("nb"), "Referansemodell")
    
    def test_get_model_description(self):
        """
        The model returns a description
        """
        instance = ReferenceModel()
        self.assertIsNotNone(instance.get_model_description())
    
    def test_get_warning_status_interpretation(self):
        """
        The model returns a warning status interpretation
        """
        instance = ReferenceModel()
        self.assertIsNotNone(instance.get_warning_status_interpretation())

    def test_get_model_usage(self):
        """
        The model returns a description of usage
        """

if __name__ == '__main__':
    unittest.main()