#pragma once

#include "xtr/io/OptionsIO.hpp"

namespace xtr::io {

//! Export RSForm as docx
class RSForm2DOCX {
  MSO::Word::WApplication wordApplication{};
  MSO::Word::WDocuments docs{};
  MSO::Word::WDocument workingDocument{};
  SchemaOptions params{};
  const ccl::semantic::RSForm& source;

public:
  explicit RSForm2DOCX(const ccl::semantic::RSForm& source)
    : source{ source } {}

public:
  BOOL Export(const SchemaOptions& exportParams, CString fileName);

private:
  [[nodiscard]] static std::optional<CString> GetPathToTemplate();

  BOOL LoadApplication();
  BOOL CreateDocument();
  
  BOOL WriteContent();
  BOOL PutTextIntoBookmark(CString bookmarkName, CString text);
  BOOL WriteHeaderFooter();
  void WriteConstituenta(EntityUID target, MSO::Word::WTable& outTable, long nRow);

  void SaveFile(CString fileName);
};

} // namespace xtr::io