/*******************************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
*******************************************************************************/
//! \file xmlEvolvedFileWriter.h
//! \ingroup omtReader
#pragma once

#include <omtReader/omtReader.h>

//! XML Tag Definitions
#include <mtl/xmlFedTags.h>
#include <mtl/fedReader.h>
#include <libxml/xmlwriter.h>

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif

struct DtOMTTreePOC;
class DtOMTTree;
class DtOMTNode;
class DtComplexComponentNode;
class DtEnumerationNode;
class DtAttributeFedNode;
class DtParameterFedNode;
class DtObjectClassFedNode;
class DtInteractionClassFedNode;
class DtFieldComponentNode;
class DtAlternativeComponentNode;
class DtDimensionNode;
class DtTimeRepNode;
class DtTagNode;
class DtSynchroNode;
class DtDescriptionNode;
class DtBoolAttrNode;
class DtUpdateRateNode;
class DtBasicDataRepresentationNode;
class DtSimpleDatatypeNode;
class DtEnumeratedDatatypeNode;
class DtEnumerationNode;
class DtArrayDatatypeNode;
class DtFixedDatatypeNode;
class DtFieldComponentNode;
class DtVariantDatatypeNode;
class DtAlternativeComponentNode;
class DtNoteNode;
struct DtOMTTreeReference;

class DT_DLL_OMTREADER DtXMLEvolvedFileWriter
{

public: 

   DtXMLEvolvedFileWriter(DtOMTTree* tree);

   //! destructor
   virtual ~DtXMLEvolvedFileWriter();

   //Use the omtTree to write out a DtString
   DtString writeString();

   //output to a file
   void writeFile(const char* fileName);

protected:

   //Functions to write out specific portions
   //of the fed file
   void writeAllXMLInformation();

   void writeVersionInformation();
   void writeModelIdentification();
   void writeName(const DtString & name);
   void writeVersionNo(const DtString & version);
   void writeType(const DtString & type);
   void writePurpose(const DtString & purpose);
   void writeApplicationDomain(const DtString & AppDomain);
   void writeSponsorOrgName(xmlAttrPtr& ptr, DtOMTTree*);
   void writeModificationDate(const DtString & date);
   void writeSecurityClassification(const DtString & SecInfo);
   void writeReleaseRestriction(const DtString & Restriction);
   void writeDescription(const DtString & Description);
   void writeOther(xmlAttrPtr& ptr, DtOMTTree*);

   void writeUseLimitation(const DtString & limitation);
   void writeUseHistory(const DtString & history);

   //write out point of contact information
   void writePOCs();
   void writePOC(const DtOMTTreePOC & poc);
   void writePOCOrgName(const DtString & Org);
   void writePOCType(const DtString & type);
   void writePOCFirstName(const DtString & name);
   void writePOCPhone(const DtString & phone);
   void writePOCEmail(const DtString & email);
   void writePOCLastName(const DtString & lastName);
   void writePOCHonorificName(const DtString & honorificName);

   //write out reference information
   void writeReference(const DtOMTTreeReference& ref);
   void writeReferenceType(const DtString & RefType);
   void writeReferenceIdentification(const DtString & RefId);

   //write out all <objects> + write <attribute>
   void writeObjectClass(const DtObjectClassFedNode & obj);
   void writeObjectAttribute(const DtAttributeFedNode & attr);

   //write out all <interactions> + write <parameter>
   void writeInteractionClass(const DtInteractionClassFedNode & inter);
   void writeInteractionParameter(const DtParameterFedNode & param);

   //write <dimensions>
   void writeDimensions();
   void writeDimension(const DtDimensionNode & dim);


   //write out <time>
   void writeTime(const DtTimeRepNode & time);

   //write <tags>
   void writeTags();
   void writeTag(const DtTagNode & tag);

   //write <synchronizations>
   void writeSynchronizations();
   void writeSynchronizationPoint(const DtSynchroNode & syncro);

   //write <transportations>
   void writeTransportations();
   void writeTransportation(const DtDescriptionNode & trans);
   
   //write <switches>
   void writeSwitches();
   void writeSwitch(const DtBoolAttrNode & swtch);

   void writeUpdateRates();
   void writeUpdateRate(const DtUpdateRateNode & update);

   //write all datatypes
   void writeDataTypes();

   //write specific datatypes
   void writeBasicDataType(const DtBasicDataRepresentationNode & node);
   void writeSimpleDataType(const DtSimpleDatatypeNode & node);
   void writeEnumeratedDataType(const DtEnumeratedDatatypeNode & node);
   void writeEnumerator(const DtEnumerationNode & node);
   void writeArrayDataType(const DtArrayDatatypeNode & node);
   void writeFixedRecordDataType(const DtFixedDatatypeNode & node);
   void writeFixedRecordFields(const DtFieldComponentNode & node);
   void writeVariantRecordDataType(const DtVariantDatatypeNode & node);
   void writeVariantAlternative(const DtAlternativeComponentNode & node);

   //write notes
   void writeNotes();
   void writeNote(const DtNoteNode & node); 
   void writeEmbeddedNote(const DtOMTNode& note);
  
   //Lots of elements only have one text item
   //Helper function to write out an element with one text item
   void writeElementWithText(const DtString & elementName, const DtString & text);

protected:

   DtOMTTree* myOmtTree;
   xmlTextWriterPtr myWriter;
};

#ifdef DtUSE_UTILITIES_NAMESPACE
} // end of namespace DtUSE_UTILITIES_NAMESPACE
#endif
