/*
* Author:          Patrick-Christopher Mattulat
* Co-Author:       Claude Sonnet 4.6 (LLM)
* Company:         Lynar Studios
* E-Mail:          webmaster@lynarstudios.com
* Created:         2023-03-16
* Changed:         2026-06-23
*
* */

#include <iostream>
#include <ls-std/core/evaluator/NullPointerEvaluator.hpp>
#include <ls-std/core/jni/JniClass.hpp>
#include <ls-std/core/jni/JniClassParameter.hpp>
#include <ls-std/time/common/jni/JniDateParameterMapper.hpp>
#include <ls-std/time/system-time/SystemTime.hpp>
#include <ls-std/time/system-time/jni/com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.h>
#include <memory>

using ls::standard::core::NullPointerEvaluator;
using ls::standard::core::experimental::JniClass;
using ls::standard::core::experimental::JniClassParameter;
using ls::standard::time::DateParameter;
using ls::standard::time::SystemTime;
using ls::standard::time::experimental::JniDateParameterMapper;
using ls::standard::time::type::Day;
using ls::standard::time::type::Hour;
using ls::standard::time::type::Minute;
using ls::standard::time::type::Month;
using ls::standard::time::type::Second;
using ls::standard::time::type::Year;
using std::cout;
using std::endl;
using std::make_shared;
using std::pair;
using std::shared_ptr;
using std::string;

JNIEXPORT jboolean JNICALL Java_com_lynarstudios_ls_std_time_systemtime_SystemTimeJni_set(JNIEnv *_environment, [[maybe_unused]] jobject _object, jobject _dateParameter)
{
  const auto parameter = make_shared<JniClassParameter>();
  parameter->setJavaEnvironment(_environment);
  parameter->setJavaObject(_dateParameter);

  JniClass javaClass{parameter, "com/lynarstudios/ls/std/time/systemtime/DateParameter"};
  javaClass.load();

  javaClass.loadMethod("getYear", "()I");
  javaClass.loadMethod("getMonth", "()B");
  javaClass.loadMethod("getDay", "()B");
  javaClass.loadMethod("getHour", "()B");
  javaClass.loadMethod("getMinute", "()B");
  javaClass.loadMethod("getSecond", "()B");

  // map

  const DateParameter dateParameter = JniDateParameterMapper::toDateParameter(javaClass);
  const bool success = SystemTime{}.set(dateParameter);

  if (success)
  {
    cout << R"lit(system time successfully set to ")lit" << dateParameter.getYear() << "-" << dateParameter.getMonth() << "-" << dateParameter.getDay() << " " << dateParameter.getHour() << ":" << dateParameter.getMinute() << ":" << dateParameter.getSecond() << R"lit(" ...)lit" << endl;
  }
  else
  {
    cout << "could not set system time ..." << endl;
  }

  return success;
}
