//
// Copyright (c) 2009 Froduald Kabanza and the Université de Sherbrooke.
// Use of this software is permitted for non-commercial research purposes, and
// it may be copied or applied only for that use. All copies must include this
// copyright message.
// 
// This is a research prototype that has not gone through intensive tests and
// is delivered as is. It may still contain bugs. Froduald Kabanza and the
// Université de Sherbrooke disclaim any responsibility for damage that may be
// caused by using it.
//
// Please note that some files were inspired in part by the PDDL4J library:
// http://www.math-info.univ-paris5.fr/~pellier/software/software.php 
//
// Implementation: Simon Chamberland
// Project Manager: Froduald Kabanza
//

#ifndef _I_ACTION_H
#define _I_ACTION_H

#include "IGroundAction.h"
#include "../Exp/Term/ObjectParameterVariable.h"
#include "../../Utils/ReferenceCounted.h"

#include <string>
#include <list>

namespace planning
{
  /// <summary>
  /// This interface is implemented by all types of action defined in the PDDL language.
  /// </summary>
  class IAction : public ReferenceCounted
  {
  public:
    template <class ArgumentIterator>
    IAction(const std::string& name, ArgumentIterator argumentsBegin, ArgumentIterator argumentsEnd)
      : m_name(name), m_arguments(argumentsBegin, argumentsEnd)
    {
      memory::acquire(this, m_arguments.begin(), m_arguments.end());
    }

    virtual ~IAction()
    {
      memory::release(this, m_arguments.begin(), m_arguments.end());
    }

    const std::string& getName() const
    {
      return m_name;
    }

    //const std::vector<const ObjectParameterVariable*>& getArguments() const
    //{
    //  return m_arguments;
    //}

    void instantiateAllActions(std::vector<const IGroundAction*>& actions) const;

    typedef std::vector<const ObjectParameterVariable*>::const_iterator argument_iterator;

    argument_iterator argumentsBegin() const
    {
      return m_arguments.begin();
    }

    argument_iterator argumentsEnd() const
    {
      return m_arguments.end();
    }

  protected:
    virtual void _output(std::ostream& out) const;

    virtual IGroundAction* instantiateAction(const Bindings* bindings) const = 0;

    std::string m_name;

    std::vector<const ObjectParameterVariable*> m_arguments;

    ///// <summary>
    ///// Returns the name of the action.
    ///// </summary>
    //string Name { get; }

    ///// <summary>
    ///// Returns the priority of the action. A higher priority means the action will be chosen
    ///// first. Defining priorities is possible only in TLPlan domains.
    ///// </summary>
    //[TLPlan]
    //double Priority { get; }

    ///// <summary>
    ///// Returns all effects of the action, independently of their time of effect.
    ///// </summary>
    ///// <returns>All effects of the action.</returns>
    //IEnumerable<IEffect> GetAllEffects();

    ///// <summary>
    ///// Returns the parameters of the action.
    ///// </summary>
    ///// <returns>The parameters of the action.</returns>
    //IEnumerable<ObjectParameterVariable> GetParameters();

    ///// <summary>
    ///// Returns a typed string representation of this action.
    ///// </summary>
    ///// <returns>A typed string representation of this action.</returns>
    //string ToTypedString();
  };
}

#endif