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

#ifndef LS_STD_SERIALIZABLE_SECTION_PAIR_SECTION_HPP
#define LS_STD_SERIALIZABLE_SECTION_PAIR_SECTION_HPP

#include "SerializableSectionPairParameter.hpp"
#include <ls-std/core/Class.hpp>
#include <ls-std/core/interface/ISerializable.hpp>
#include <ls-std/io/section-pair/SectionPairRowEnumType.hpp>
#include <ls-std/os/dynamic-goal.hpp>
#include <string_view>

/*
 * @doc: class(name: 'SerializableSectionPairSection', package: 'io')
 * @doc: io.SerializableSectionPairSection.description('This class can serialize a Section Pair section for file persistence.')
 * */

namespace ls::standard::io
{
  class LS_STD_DYNAMIC_GOAL SerializableSectionPairSection : public ls::standard::core::interface_type::ISerializable, public ls::standard::core::Class
  {
    public:

      explicit SerializableSectionPairSection(const ls::standard::io::SerializableSectionPairParameter &_parameter);
      ~SerializableSectionPairSection() noexcept override;

      [[nodiscard]] ::std::shared_ptr<ls::standard::core::Class> getValue() const;
      [[nodiscard]] ls::standard::core::type::byte_field marshal() override;
      void unmarshal(const ls::standard::core::type::byte_field &_data) override;

    private:

      ls::standard::io::SerializableSectionPairParameter parameter{};

      [[nodiscard]] ls::standard::core::type::byte_field _collectSectionRow(const ls::standard::core::type::byte_field &_currentRows, ls::standard::io::SectionPairRowEnumType &_type) const;
      [[nodiscard]] ls::standard::core::type::byte_field _collectSectionListValueRow(const core::type::byte_field &_currentRows, ls::standard::io::SectionPairRowEnumType &_type) const;
      [[nodiscard]] static core::type::byte_field _collectSectionSingleValueRow(const ls::standard::core::type::byte_field &_firstRow, ls::standard::io::SectionPairRowEnumType &type);
      [[nodiscard]] static size_t _getNthSubStringPosition(::std::string_view _text, ::std::string_view _subText);
      [[nodiscard]] ls::standard::core::type::byte_field _getSectionHeader(const ls::standard::core::type::byte_field &_data) const;
      [[nodiscard]] static ls::standard::core::type::byte_field _getSectionId(::std::string_view _sectionHeader);
      [[nodiscard]] static bool _isListValueRow(::std::string_view _currentRow);
      [[nodiscard]] static bool _isStartingValueRow(const ::std::string &_currentRow);
      [[nodiscard]] static bool _isSingleValueRow(::std::string_view _currentRow);
      [[nodiscard]] ls::standard::core::type::byte_field _marshalRows() const;
      [[nodiscard]] ls::standard::core::type::byte_field _marshalSectionId() const;
      void _unmarshalRow(const ::std::string &_sectionRow, ls::standard::io::SectionPairRowEnumType _type) const;
      void _unmarshalRows(const ls::standard::core::type::byte_field &_serializedRows) const;
      [[nodiscard]] size_t _unmarshalSectionHeader(const ls::standard::core::type::byte_field &_data) const;
  };
}

#endif
