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

#ifndef LS_STD_SECTION_PAIR_DOCUMENT_HPP
#define LS_STD_SECTION_PAIR_DOCUMENT_HPP

#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/SectionPairDocumentTypes.hpp>
#include <ls-std/os/dynamic-goal.hpp>
#include <memory>
#include <string_view>

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

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

      SectionPairDocument();
      ~SectionPairDocument() noexcept override;

      void add(const ls::standard::io::section_pair_document_section_list_element &_section);
      void clear();
      [[nodiscard]] ls::standard::io::section_pair_document_section_list_element get(size_t _index) const;
      [[nodiscard]] ls::standard::io::section_pair_document_section_list_element get(const ls::standard::io::section_pair_identifier &_sectionId) const;
      [[nodiscard]] size_t getAmountOfSections() const;
      [[nodiscard]] ::std::string getHeader() const;
      [[nodiscard]] ls::standard::io::section_pair_document_section_list getSectionList() const;
      [[nodiscard]] bool hasSection(const ls::standard::io::section_pair_identifier &_sectionId);
      [[nodiscard]] ls::standard::core::type::byte_field marshal() override;
      void reserveNewLine(::std::string_view _reservedNewLine);
      void unmarshal(const ls::standard::core::type::byte_field &_data) override;

    private:

      const ::std::string header = "# section-pair document";
      ::std::string reservedNewLine{};
      ls::standard::io::section_pair_document_section_list sections{};
      ::std::shared_ptr<ls::standard::core::interface_type::ISerializable> serializable{};

      void _checkSectionExistence(const ls::standard::io::section_pair_identifier &_sectionId);
      void _createSerializable();
      [[nodiscard]] ls::standard::io::section_pair_document_section_list_element _get(const ls::standard::io::section_pair_identifier &_sectionId) const;
      [[nodiscard]] bool _hasSection(const ls::standard::io::section_pair_identifier &_identifier);
  };
}

#endif
