/** \file
 *
 *  Contains the WaitDepth class declaration.
 *
 *  WaitDepth.h should only be included by WaitDepth.cpp
 *  Other classes should include WaitDepthIF.h
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef WAITDEPTH_H_
#define WAITDEPTH_H_

#include "component/Behavior.h"
#include "data/Location.h"

class UniversalDataReader;

/**
 *  Contains the WaitDepth Command
 *
 *  Is not satisfied until the specified depth has
 *  been reached.
 *
 *  WaitDepth.h should only be included by WaitDepth.cpp
 *  Other classes should include WaitDepthIF.h
 *
 *  \ingroup modules_guidance
 */
class WaitDepth : public Behavior
{
public:

    WaitDepth( const Str& prefix, const Module* module );

    virtual ~WaitDepth();

    /// Initialize function
    void initialize( void );

    /// The actual "payload" of the component
    void run();

    /// Runs and returns false if not in range of target depth
    /// Otherwise returns true
    bool runIfUnsatisfied();

    /// Returns true when vehicle has "arrived"
    /// within the deadband of the target depth
    bool isSatisfied();

    /// Uninit function
    void uninitialize( void );

    /// Mission Component factory interface
    static Behavior* CreateBehavior( const Str& prefix, const Module* module );

protected:

    // Timeout
    Timestamp startTime_;
    Timespan timeoutDuration_;
    float durationSeconds_;

    // Target depth
    float targetDepth_;
    float depthTol_;  // tolerance or deadband around target depth


    // Behavior setting readers

    /// Target depth setting
    SettingReader *targetDepthSettingReader_;
    SettingReader *depthDeadbandSettingReader_;

    /// Timeout setting
    SettingReader *timeoutDurationSettingReader_;

    /// Current depth (in meter from sea surface -- positive down)
    UniversalDataReader *depthReader_;

    /// Return true if the waiting time is over
    bool calcSatisfied( const float param );

    /// Read in the parameters for satisfied or runIfUnsatisfied: return true if OK.
    bool readParams( float& param );

    // Reads in behavior settings
    void readSettings();

private:
    // Note that the copy constructor below is private and not given a body.
    // Any attempt to call it will return a compiler error.
    WaitDepth( const WaitDepth& old ); // disallow copy constructor

};

#endif /*WAITDEPTH_H_*/
