/*
* 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/SectionPairRowSingleValueValidator.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::SectionPairRowSingleValueValidator;
using ls::standard::io::SectionPairValueValidator;
using std::move;
using std::regex;
using std::regex_match;
using std::string;

SectionPairRowSingleValueValidator::SectionPairRowSingleValueValidator(string _singleValueRow) : Class("SectionPairRowSingleValueValidator"), singleValueRow(::move(_singleValueRow))
{}

SectionPairRowSingleValueValidator::~SectionPairRowSingleValueValidator() noexcept = default;

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

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

  return regex_match(this->singleValueRow, singleValueRowRegex);
}

string SectionPairRowSingleValueValidator::_getValidationRegex()
{
  const string identifierRegex = SectionPairIdentifierValidator::getValidationRegex();
  const string valueRegex = SectionPairValueValidator::getValidationRegex();

  return R"(()" + identifierRegex + R"()={1}()" + valueRegex + R"(){1}($|\n{1}|\r{1}\n{1}))";
}
