#pragma once

#include "xtr/doc/Documents.h"
#include "xtr/io/SerializationManager.hpp"

namespace xtr::doc {

class RSFormDoc;

//! RSModel document
class RSModelDoc final 
  : public SelectableDoc, public io::MFCSerializable<RSMVersion>, public ccl::types::Observer {
  DECLARE_DYNCREATE(RSModelDoc)

private:
  ccl::semantic::RSModel model{};

public:
  ~RSModelDoc() override;

private:
  RSModelDoc();

public:
  void OnObserve(const ccl::types::Message& change) override;

public:
  ccl::semantic::RSModel& Model() noexcept { return model; }
  const ccl::semantic::RSModel& Model() const noexcept { return model; }

public:
  void Serialize(CArchive& ar) override;
  BOOL OnNewDocument() override;
  BOOL OnOpenDocument(LPCTSTR path) override;
  BOOL OnSaveDocument(LPCTSTR path) override;

private:
  JSON ExtractData() const override;
  bool LoadData(const JSON& object) override;
  bool LegacyLoad(io::CArchiveAdapter& archive) override;
};

} // namespace xtr::doc