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

#ifndef LS_STD_SECTION_PAIR_SECTION_HPP
#define LS_STD_SECTION_PAIR_SECTION_HPP

#include <list>
#include <ls-std/core/Class.hpp>
#include <ls-std/core/interface/ISerializable.hpp>
#include <ls-std/io/section-pair/SectionPairTypes.hpp>
#include <ls-std/io/section-pair/type/SectionPairSectionTypes.hpp>
#include <ls-std/os/dynamic-goal.hpp>
#include <memory>
#include <string>
#include <string_view>

/*
 * @doc: class(name: 'SectionPairSection', package: 'io')
 * @doc: io.SectionPairSection.description('This class represents a Section Pair section.')
 * */

namespace ls::standard::io
{
  class LS_STD_DYNAMIC_GOAL SectionPairSection : public ::std::enable_shared_from_this<SectionPairSection>, public ls::standard::core::Class, public ls::standard::core::interface_type::ISerializable
  {
    public:

      explicit SectionPairSection(const ls::standard::io::section_pair_identifier &_sectionId);
      ~SectionPairSection() noexcept override;

      void add(const ls::standard::io::section_pair_row_list_element &_row);
      void clear();
      [[nodiscard]] ls::standard::io::section_pair_row_list_element get(size_t _index) const;
      [[nodiscard]] ls::standard::io::section_pair_row_list_element get(const ls::standard::io::section_pair_identifier &_key) const;
      [[nodiscard]] ls::standard::io::section_pair_row_list getList() const;
      [[nodiscard]] size_t getRowAmount() const;
      [[nodiscard]] ls::standard::io::section_pair_identifier getSectionId() const;
      [[nodiscard]] bool hasRow(const ls::standard::io::section_pair_identifier &_key);
      [[nodiscard]] ls::standard::core::type::byte_field marshal() override;
      void reserveNewLine(::std::string_view _reservedNewLine);
      void setSectionId(const ls::standard::io::section_pair_identifier &_sectionId);
      void unmarshal(const ls::standard::core::type::byte_field &_data) override;

    private:

      ::std::string reservedNewLine{};
      ls::standard::io::section_pair_row_list rows{};
      ls::standard::io::section_pair_identifier sectionId{};
      ::std::shared_ptr<ls::standard::core::interface_type::ISerializable> serializable{};

      void _createSerializable();
      [[nodiscard]] ls::standard::io::section_pair_row_list_element _get(const ls::standard::io::section_pair_identifier &_key) const;
      [[nodiscard]] bool _hasRow(const ls::standard::io::section_pair_identifier &_key);
      void _rowExistenceCheck(const ls::standard::io::section_pair_identifier &_key);
      void _setSectionId(const ls::standard::io::section_pair_identifier &_sectionId);
  };
}

#endif
