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

#include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
#include <ls-std/io/section-pair/model/SectionPairRowSingleValue.hpp>
#include <ls-std/io/section-pair/serialization/SerializableSectionPairRowSingleValue.hpp>

using ls::standard::core::Class;
using ls::standard::core::EmptyStringArgumentEvaluator;
using ls::standard::core::NullPointerArgumentEvaluator;
using ls::standard::core::type::byte_field;
using ls::standard::io::SectionPairRowSingleValue;
using ls::standard::io::SerializableSectionPairParameter;
using ls::standard::io::SerializableSectionPairRowSingleValue;
using std::dynamic_pointer_cast;
using std::shared_ptr;
using std::string;

SerializableSectionPairRowSingleValue::SerializableSectionPairRowSingleValue(const SerializableSectionPairParameter &_parameter) : Class("SerializableSectionPairRowSingleValue"), parameter(_parameter)
{
  const string message = this->getClassName() + ": model reference is null!";
  NullPointerArgumentEvaluator{_parameter.getValue(), message}.evaluate();
}

SerializableSectionPairRowSingleValue::~SerializableSectionPairRowSingleValue() noexcept = default;

shared_ptr<Class> SerializableSectionPairRowSingleValue::getValue() const
{
  return this->parameter.getValue();
}

byte_field SerializableSectionPairRowSingleValue::marshal()
{
  return dynamic_pointer_cast<SectionPairRowSingleValue>(this->parameter.getValue())->get() + this->parameter.getNewLine();
}

void SerializableSectionPairRowSingleValue::unmarshal(const byte_field &_data)
{
  EmptyStringArgumentEvaluator{_data}.evaluate();
  dynamic_pointer_cast<SectionPairRowSingleValue>(this->parameter.getValue())->set(_data);
}
