#pragma once

#include "fan.hpp"
#include "rpolicy.hpp"

#include <functional>
#include <vector>

namespace phosphor
{
namespace fan
{
namespace presence
{

class PresenceSensor;

/**
 * @class Fallback
 * @brief Fallback redundancy policy.
 *
 * The fallback redundancy policy falls back to
 * subsequent presence sensors when the active
 * sensor indicates not present and a fallback
 * sensor indicates the fan is present.
 */
class Fallback : public RedundancyPolicy
{
  public:
    Fallback() = delete;
    Fallback(const Fallback&) = default;
    Fallback& operator=(const Fallback&) = default;
    Fallback(Fallback&&) = default;
    Fallback& operator=(Fallback&&) = default;
    ~Fallback() = default;

    /**
     * @brief Construct a fallback policy.
     *
     * @param[in] fan - The fan associated with the policy.
     * @param[in] s - The set of sensors associated with the policy.
     * @param[in] e - EEPROM device instance
     */
    Fallback(const Fan& fan,
             const std::vector<std::reference_wrapper<PresenceSensor>>& s,
             std::unique_ptr<EEPROMDevice> e) :
        RedundancyPolicy(fan, std::move(e)),
        sensors(s)
    {
        activeSensor = sensors.begin();
    }

    /**
     * @brief Construct a fallback policy.
     *
     * @param[in] fan - The fan associated with the policy.
     * @param[in] s - The set of sensors associated with the policy.
     */
    Fallback(const Fan& fan,
             const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
        Fallback(fan, s, nullptr)
    {}

    /**
     * @brief stateChanged
     *
     * Update the inventory and execute the fallback
     * policy.
     *
     * @param[in] present - The new presence state according
     *             to the active sensor.
     * @param[in] sensor - The sensor that changed state.
     */
    void stateChanged(bool present, PresenceSensor& /*sensor*/) override;

    /**
     * @brief monitor
     *
     * Start monitoring the fan.
     */
    void monitor() override;

  private:
    /** @brief All presence sensors in the redundancy set. */
    std::vector<std::reference_wrapper<PresenceSensor>> sensors;

    /** @brief The active presence sensor. */
    decltype(sensors)::iterator activeSensor;
};

} // namespace presence
} // namespace fan
} // namespace phosphor
