#pragma once

namespace xtr { class ExteorApplication; }

namespace xtr::doc {

struct XTRDocument;
class RSFormDoc;
class OSSDoc;
class RSModelDoc;

//! Exteor documents manager
class DocumentManager {
  friend class xtr::ExteorApplication;

  ExteorApplication& exteor;
  CMultiDocTemplate* m_RSFormTemplate{ nullptr };
  CMultiDocTemplate* m_RSModelTemplate{ nullptr };
  CMultiDocTemplate* m_OSSTemplate{ nullptr };

public:
  explicit DocumentManager(ExteorApplication& app) noexcept
    : exteor{ app } {}

public:
  void ShowDocument(doc::XTRDocument& doc);

  doc::RSFormDoc* NewRSFormDoc(const ccl::semantic::RSForm& schema, BOOL noView = FALSE);
  doc::RSFormDoc* NewRSFormDoc(BOOL noView = FALSE);
  doc::RSModelDoc* NewRSModelDoc(BOOL noView = FALSE);
  doc::OSSDoc* NewOSSDoc(BOOL noView = FALSE);

  [[nodiscard]] doc::RSFormDoc* OpenRSFormDoc(CString path, BOOL noView = FALSE);

  [[nodiscard]] std::vector<const ccl::semantic::RSForm*> RSFormList() const;
  [[nodiscard]] std::vector<const ccl::semantic::RSModel*> RSModelList() const;
  [[nodiscard]] std::vector<const doc::RSFormDoc*> RSFormDocList() const;

  [[nodiscard]] doc::RSFormDoc* FindRSDocByPath(CString path);

private:
  BOOL Initialize();

  static CDocument* NewDoc(CMultiDocTemplate& templ, BOOL noView);
  static CDocument* OpenDoc(CMultiDocTemplate& templ, CString path, BOOL noView);
  BOOL CreateViewFor(doc::XTRDocument& doc);
};

} // namespace xtr::doc