/** \file
 *
 *  Contains the ScheduledItem class declaration.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 *  Created on: Dec 3, 2013
 *  Author: godin
 *
 */

#include "utils/Str.h"
#include "utils/Timestamp.h"

#ifndef SCHEDULEDITEM_H_
#define SCHEDULEDITEM_H_

class ScheduledItem
{
    friend class Scheduler;

public:

    typedef enum
    {
        NONE,
        ASAP,
        NEXT,
        TIMED
    } ScheduledType;

    Str ScheduledTypeToString( ScheduledType type )
    {
        switch( type )
        {
        case ScheduledItem::ASAP:
            return "ASAP";
        case ScheduledItem::NEXT:
            return "AFTER MISSION";
        case ScheduledItem::TIMED:
            return "AT TIME: " + execTime_.toString( 0 );
        case ScheduledItem::NONE:
            return "";
        default:
            return "(undefined)";
        }
    };

    ScheduledItem( const Str& cmd, const Str& id, int idIndex, int idCount );

    virtual ~ScheduledItem() {}

    Str& getCmd()
    {
        return cmd_;
    }
    int getIndex()
    {
        return index_;
    }
    Str& getId()
    {
        return id_;
    }
    int getIdIndex()
    {
        return idIndex_;
    }
    int getIdCount()
    {
        return idCount_;
    }
    ScheduledType& getType()
    {
        return type_;
    }
    bool isReady()
    {
        return ready_;
    }
    bool isExecuted()
    {
        return executed_;
    }
    Timestamp& getExecTime()
    {
        return execTime_;
    }
    Str typeToStr()
    {
        return ScheduledTypeToString( type_ );
    }
    Str report();

protected:

    void setIndex( int index )
    {
        index_ = index;
    }
    void markReady( bool ready = true )
    {
        ready_ = ready;
    }
    void markExecuted( bool executed = true )
    {
        executed_ = executed;
    }

    Str cmd_;
    int index_;
    Str id_;
    int idIndex_;
    int idCount_;
    bool ready_;
    Timestamp execTime_;
    bool executed_;
    ScheduledType type_;

};

class ScheduledItemASAP: public ScheduledItem
{
public:
    ScheduledItemASAP( const Str& cmd, const Str& id, int idIndex, int idCount );
};

class ScheduledItemNext: public ScheduledItem
{
public:
    ScheduledItemNext( const Str& cmd, const Str& id, int idIndex, int idCount );
};

class ScheduledItemTimed: public ScheduledItem
{
public:
    ScheduledItemTimed( const Timestamp& execTime, const Str& cmd, const Str& id, int idIndex, int idCount );
};

#endif /* SCHEDULEDITEM_H_ */
