//////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2025 Autodesk, Inc.  All rights reserved.
//
//  Use of this software is subject to the terms of the Autodesk license 
//  agreement provided at the time of installation or download, or which 
//  otherwise accompanies this software in either electronic or hard copy form.   
//
//////////////////////////////////////////////////////////////////////////////

#ifndef ACMREVISIONLIST_H
#define ACMREVISIONLIST_H

#include "AcmTitle.h"

#include <vector>
#include <string>
#include <map>

#include <AcString.h>

class AcMgRevisionList;
class AcMgRevisionLists;
class AcMgRevisionListContext;
class AcMgRevisionListAttribMap;
class AcMgRevisionListDescriptor;

#define REVLINE_ATTRIB_NR               _T(/*MSG0*/"GEN-REV-NR")
#define REVLINE_ATTRIB_DAT              _T(/*MSG0*/"GEN-REV-DAT")
#define REVLINE_ATTRIB_TEXT1            _T(/*MSG0*/"GEN-REV-TEXT1")
#define REVLINE_ATTRIB_TEXT2            _T(/*MSG0*/"GEN-REV-TEXT2")
#define REVLINE_ATTRIB_NAME             _T(/*MSG0*/"GEN-REV-NAME")
#define REVLINE_ATTRIB_BLK              _T(/*MSG0*/"GEN-REV-BLK")

///<summary><para>The manager class maintains all the revision lists in opened drawing(s).</para><para>
///This class is derived from AcRxService which provides revision list related service, like create, delete, 
///and retrieve the revision list object in the drawing. 
///Retrieve the only instance of this class as other registered services which derive from AcRxService.</para></summary>
class AMGTITLE_DLLSHARE AcMgRevisionMgr : public AcRxService
{
public:
  ///<summary>Create/new a descriptor object with default settings. 
  ///The descriptor object is ref-count and the reference count is internally increased. 
  ///Please call its Release() to decrease the reference count when you don��t need it. </summary>
  virtual AcMgRevisionListDescriptor* NewDescriptor()=0;

  ///<summary>Create/new a attribute map object. </summary>
  virtual AcMgRevisionListAttribMap* NewAttributeMap() = 0;

  ///<summary>Create a new revision list or append a revision list item to existing global revsion list in current drawing
  ///  with settings specified by the descriptor object and context object. </summary>
  ///<param name="pDesc">Pointer to the descriptor object which contains all the settings for creating a new revision list. </param>
  ///<param name="pCont">Pointer to context object. DON'T specify this as it has been deprecated and keep default null pointer . </param>
  virtual AcDbObjectId CreateRevisionList(AcMgRevisionListDescriptor* pDesc, 
                                          AcMgRevisionListContext* pCont = NULL) = 0;

  ///<summary>Retrieve the revision list object via its object id or its entity part.</summary>
  ///<param name="ObjId">The object id of the revision list itself or its entity part. </param>
  ///<returns><para>If successful then the revision list object is returned. Otherwise null pointer is returned. </para><para>
  ///Be noticed that the revision list object is ref-count and the reference count is internally increased. 
  ///Please call its Release() to decrease the reference count when you don't need it.</para></returns>
  virtual AcMgRevisionList* GetRevListFromRef(AcDbObjectId& ObjId)=0;

  ///<summary>Delete the revision list object specified by its object id.</summary>
  ///<param name="revListId">The object id of the revision list which will be deleted. </param>
  ///<returns>If successful then return true. Otherwise false is returned.</returns>
  virtual bool DeleteRevisionList(const AcDbObjectId& revListId)=0;

  ///<summary>Delete the revision list object specified by its index in the manager object.</summary>
  ///<param name="index">the index of the revision list which will be deleted. </param>
  ///<returns>If successful then return true. Otherwise false is returned.</returns>
  virtual bool DeleteRevisionList(const VARIANT& index)=0;

  ///<summary>Retrieve the collection object which contains all the revision list objects maintained by the manager object.</summary>
  ///<param name="pLists">the returned collection object with AcMgRevisionLists type. </param>
  ///<returns>the returned collection object with AcMgRevisionLists type. </returns>
  virtual bool GetRevisionLists(AcMgRevisionLists*& pLists)=0;

public:
  ///<summary>Deprecated API!</summary>
  virtual bool GetAutoControl() = 0;
  ///<summary>Deprecated API!</summary>
  virtual void SetAutoControl(const bool on) = 0;
  virtual AcMgRevisionListContext* NewContext() = 0;

protected:
  ///<summary>This destructor is protected.</summary>
  virtual ~AcMgRevisionMgr() {}   
};

///<summary>The instance of this class specifies the container object which manages and contains all the attributes of revision list item. 
///This class provides methods to get/set particular attribute values via its key, 
///and get the key and its value via its index of the attribute collection.</summary>
class AMGTITLE_DLLSHARE AcMgRevisionListAttribMap {
public:
  ///<summary>Increase the reference count by one.</summary>
  virtual ULONG AddRef() = 0;
  ///<summary>Decrease the reference count by one and delete it when reference count is zero.</summary>
  virtual ULONG Release() = 0;

  ///<summary>Return the count of attributes.</summary>
  virtual int   Count() const   = 0;
  ///<summary>Get the particular attribute value via its key. The returned attribute value is specified as string. 
  ///The method returns true for success, otherwise false.</summary>
  virtual bool  GetAt(const AcString& strKey, AcString& strValue) const = 0;
  ///<summary>Get the attribute key and value via its index. The returned attribute key and value are specified as string. 
  ///The method returns true for success, otherwise false.</summary>
  virtual bool  GetAt(int index, AcString& strKey, AcString& strValue) const = 0;
  ///<summary>Set the particular attribute value via its key. The attribue key and value are specified as string. 
  ///The method returns true for success, otherwise false.</summary>
  virtual bool  SetAt(const AcString& strKey, const AcString& strValue) = 0;

protected:
  ///<summary>The destructor is protected.</summary>
  virtual ~AcMgRevisionListAttribMap() {}
};


///<summary>The instance of this class represents the revision list object in the drawing and provides the methods to manipulate the revision list object. 
///The instance of this class is reference-counted.</summary>
class AMGTITLE_DLLSHARE AcMgRevisionList
{
public:
  ///<summary>Increase the reference count by one.</summary>
  virtual ULONG AddRef() = 0;
  ///<summary>Decrease the reference count by one and delete it when reference count is zero.</summary>
  virtual ULONG Release() = 0;

  ///<summary>Return the items for this revision list object.</summary>
  virtual int  totalItem()= 0;

  ///<summary>Return the attributes of the particular revision item specified by its index in the revision list. 
  ///Please release the attribute map object via its Release() when you don't need it.</summary>
  ///<param name="index">the revision item index. </param>
  ///<param name="pAttributesMap ">The output pointer to the attribute map object. </param>
  virtual bool item(int index, AcMgRevisionListAttribMap*& pAttributesMap) = 0;

  ///<summary>Append a revision list item specified by its attributes into the revision list.</summary>
  ///<param name="pAttributesMap ">The input pointer to the attribute map object for the revision item. </param>
  virtual bool add(const AcMgRevisionListAttribMap* pAttributesMap) = 0;

  ///<summary>Change the attributes of the particular revision list item specified by its index in the revision list.</summary>
  ///<param name="index">the revision item index. </param>
  ///<param name="pAttributesMap">The input pointer to the attribute map object for the revision item. </param>
  virtual bool set(int index, const AcMgRevisionListAttribMap* pAttributesMap) = 0;

  ///<summary>Return the object Id of the revision list.</summary>
  virtual bool RevListId(AcDbObjectId& RevId)=0;
  ///<summary>Return the attached title/border id for this revision list. Null Id is returned when no title/border is attached.</summary>
  virtual void Border(AcDbObjectId& bordId) = 0;
  ///<summary>Return the position of this revision list.</summary>
  virtual void Point(AcGePoint3d& point) = 0;

protected:
  ///<summary>The destructor is protected.</summary>
  virtual ~AcMgRevisionList() {
  }
};


///<summary>The instance of this class is to specify the settings to create new revision list. 
///The settings are position, title/border object, and the attributes. 
///To Create a new instance of this class via the revision list manger object.</summary>
class AMGTITLE_DLLSHARE AcMgRevisionListDescriptor
{
public:
  ///<summary>Increase the reference count by one.</summary>
  virtual ULONG AddRef() = 0;
  ///<summary>Descrease the reference count by one and delete it when reference count is zero.</summary>
  virtual ULONG Release() = 0;

  ///<summary>Return the specified title/border object Id. The object Id will be null if no title/border object is attached.</summary>
  virtual AcDbObjectId* Border()                = 0;
  ///<summary>Return the specified position.</summary>
  virtual AcGePoint3d*  Position()              = 0;
  ///<summary>Specify the title/border object id which the revision list will be attached. The setting will be applied when creating a new revision list.</summary>
  virtual int setBorder(const AcDbObjectId& brdId)  = 0;
  ///<summary>Specify the position which the revision list will be placed. The setting will be applied when creating a new revision list.</summary>
  virtual int setPosition(const AcGePoint3d& pos) = 0;

  ///<summary>Return the attributes maintained by the descriptor object. For a newly created descriptor object with default settings, 
  ///calling the function first time will populate all the attributes with attribute name and empty attribute value.
  ///  Release the attribute map object via its Release() when you don��t need it. C++ Syntax</summary>
  virtual void Attributes(AcMgRevisionListAttribMap*& pAttributeMap) = 0;
  ///<summary>Updates the attributes maintained by the descriptor object. The setting will be applied when creating a new revision list.</summary>
  virtual bool setAttributes(const AcMgRevisionListAttribMap* pAttributeMap) = 0;

protected:
  ///<summary>The destructor is protected.</summary>
  virtual ~AcMgRevisionListDescriptor() {}
};


///<summary>This is class AcMgRevisionListContext.</summary>
class AMGTITLE_DLLSHARE AcMgRevisionListContext
{
public:
  virtual ULONG AddRef()=0;
  virtual ULONG Release()=0;
  virtual bool inputPosition()=0;
  virtual bool inputBorder()=0;
  virtual void setInputPosition( bool newValue )=0;
  virtual void setInputBorder( bool newValue )=0;

protected:
  virtual ~AcMgRevisionListContext() {}
};


///<summary>This class works as the collection object which contains all the revision list objects maintained by the revision list manager object. 
///To Create a new instance of this class via the revision list manger object.</summary>
class AMGTITLE_DLLSHARE AcMgRevisionLists
{   
public:
  ///<summary>Increase the reference count by one.</summary>
  virtual ULONG AddRef()  = 0;
  ///<summary>Descrease the reference count by one and delete it when reference count is zero.</summary>
  virtual ULONG Release() = 0;

  ///<summary>Returns the element count in this collection object.</summary>
  virtual int   Count() const   =0;

  ///<summary><para>Return the particular revision list object specified by its index in the collection object. </para><para>
  ///Be noticed that the revision list object is ref-count and the reference count is internally increased. 
  ///Please call its Release() to decrease the reference count when you don't need it.</para></summary>
  virtual AcMgRevisionList* item(int n) = 0;

protected:
  ///<summary>The destructor is protected.</summary>
  virtual ~AcMgRevisionLists() {}
};


#define ACMG_REVISION_SERVICE _T(/*MSG0*/"AcMgRevisionService")
#define pAcMgRevListMgr ((AcMgRevisionMgr*)AcRxService::cast(acrxServiceDictionary->at( ACMG_REVISION_SERVICE )))

#endif