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

#include <ls-std/io/section-pair/validator/SectionPairIdentifierValidator.hpp>
#include <ls-std/io/section-pair/validator/SectionPairRowListValueValidator.hpp>
#include <ls-std/io/section-pair/validator/SectionPairValueValidator.hpp>
#include <regex>

using ls::standard::core::Class;
using ls::standard::io::SectionPairIdentifierValidator;
using ls::standard::io::SectionPairRowListValueValidator;
using ls::standard::io::SectionPairValueValidator;
using std::move;
using std::regex;
using std::regex_match;
using std::string;

SectionPairRowListValueValidator::SectionPairRowListValueValidator(string _listValueRow) : Class("SectionPairRowListValueValidator"), listValueRow(::move(_listValueRow))
{}

SectionPairRowListValueValidator::~SectionPairRowListValueValidator() noexcept = default;

string SectionPairRowListValueValidator::getValidationRegex()
{
  return _getValidationRegex();
}

bool SectionPairRowListValueValidator::isValid()
{
  const string validationRegex = _getValidationRegex();
  static auto listValueRowRegex = regex{"^" + validationRegex};

  return regex_match(this->listValueRow, listValueRowRegex);
}

string SectionPairRowListValueValidator::_getValidationRegex()
{
  const string identifierRegex = SectionPairIdentifierValidator::getValidationRegex();
  const string valueRegex = SectionPairValueValidator::getValidationRegex();
  const string lineBreak = R"(((\n{1})|(\r{1}\n{1})))";
  const string firstLine = R"(((()" + identifierRegex + R"():{1}))" + lineBreak + R"())";

  return R"((()" + firstLine + R"(( {2})" + valueRegex + R"()" + lineBreak + R"()){1}(( {2})" + valueRegex + R"()" + lineBreak + R"()*)))";
}
