/*********************************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc.
** All rights reserved.
*********************************************************************************/

#pragma once

//! \file linkStrategy.h
//! \ingroup managedInterface
//! \brief Defines the base class for all strategies.  Strategies are used to encapsulate
//! some aspect of VR-Link and handle the interactions for that aspect with C#

#include "managedInterface/plugin.h"

#include <vlutil/vlPrint.h>

#include <string>
#include <list>

class DtMessage;
class DtManagedInterface;

//! \brief This is the DtLinkStrategy class.  It is the abstract base class for all derived strategies
class MANAGEDINTERFACE_DLL DtLinkStrategy
{
public:
   //! \brief constructor takes name
   DtLinkStrategy(const std::string& name, DtManagedInterface* link);

   //! \brief destructor
   virtual ~DtLinkStrategy();

   //! \brief Get the name of the strategy
   std::string name();

   //! \brief Initialize the strategy.  This function will be called multiple times to allow for dependent strategies to startup properly
   //! This function should return false if the strategy cannot get a resource it needs due to a dependency not being initialized yet.
   virtual bool init()=0;
   
   //! \brief Tick the strategy to give it some CPU time
   virtual void tick();

   //! \brief Shutdown the strategy and release any resources
   virtual void shutdown();

   //! \brief Functions for adding, removing or finding any child strategies
   //! This is typically used for the initialization strategy that "owns" all the other strategies
   //{@
   virtual void addChildStrategy(DtLinkStrategy* strategy);
   virtual bool removeChildStrategy(const std::string& name);
   virtual DtLinkStrategy* findStrategy(const std::string& name);
   //@}

   //! Combine the given host global/entity identifiers, embedded index, and optional descriptor
   //! to form the value of the given embedded key
   //! Return the embedded key
   virtual std::string& makeEmbeddedKey(std::string& embeddedKey,
      const std::string& hostGlobalId, unsigned embeddedIndex, const char* descriptor=nullptr);

protected:
   DtManagedInterface* myManagedInterface;
   std::string myName;
   std::string myEmbeddedKey; // Used in makeEmbeddedKey as convenient scratch pad

   bool myInitalized;

   std::list<DtLinkStrategy*> myChildStrategies;
};
