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

#include <gtest/gtest.h>
#include <ls-std/ls-std-core.hpp>
#include <ls-std/ls-std-io.hpp>

using ls::standard::core::IllegalArgumentException;
using ls::standard::core::type::byte_field;
using ls::standard::io::NewLine;
using ls::standard::io::SectionPairRowEnumType;
using ls::standard::io::SectionPairRowSingleValue;
using std::make_shared;
using std::shared_ptr;
using testing::Test;

namespace
{
  class SectionPairRowSingleValueTest : public Test
  {
    public:

      SectionPairRowSingleValueTest() = default;
      ~SectionPairRowSingleValueTest() override = default;
  };

  TEST_F(SectionPairRowSingleValueTest, constructor_empty_value)
  {
    EXPECT_THROW(
        {
          try
          {
            SectionPairRowSingleValue value{""};
          }
          catch (const IllegalArgumentException &_exception)
          {
            throw;
          }
        },
        IllegalArgumentException);
  }

  TEST_F(SectionPairRowSingleValueTest, constructor_invalid_value)
  {
    EXPECT_THROW(
        {
          try
          {
            SectionPairRowSingleValue value{"=33"};
          }
          catch (const IllegalArgumentException &_exception)
          {
            throw;
          }
        },
        IllegalArgumentException);
  }

  TEST_F(SectionPairRowSingleValueTest, get)
  {
    const SectionPairRowSingleValue value{"blue"};
    ASSERT_STREQ("blue", value.get().c_str());
  }

  TEST_F(SectionPairRowSingleValueTest, getClassName)
  {
    ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
  }

  TEST_F(SectionPairRowSingleValueTest, getType)
  {
    SectionPairRowSingleValue value{"blue"};
    ASSERT_EQ(SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  }

  TEST_F(SectionPairRowSingleValueTest, marshal)
  {
    const auto value = make_shared<SectionPairRowSingleValue>("empty");
    const byte_field expected = "empty" + NewLine::get();
    const byte_field actual = value->marshal();

    ASSERT_STREQ(expected.c_str(), actual.c_str());
  }

  TEST_F(SectionPairRowSingleValueTest, set_empty_value)
  {
    SectionPairRowSingleValue value{"empty"};

    EXPECT_THROW(
        {
          try
          {
            value.set("");
          }
          catch (const IllegalArgumentException &_exception)
          {
            throw;
          }
        },
        IllegalArgumentException);
  }

  TEST_F(SectionPairRowSingleValueTest, set_invalid_value)
  {
    SectionPairRowSingleValue value{"empty"};

    EXPECT_THROW(
        {
          try
          {
            value.set("=33");
          }
          catch (const IllegalArgumentException &_exception)
          {
            throw;
          }
        },
        IllegalArgumentException);
  }

  TEST_F(SectionPairRowSingleValueTest, unmarshal)
  {
    const auto value = make_shared<SectionPairRowSingleValue>("empty");
    value->unmarshal("blue");

    ASSERT_STREQ("blue", value->get().c_str());
  }
}
