## This file is a template, the comment below is emitted into the generated file
/* This is an auto generated file. Do not edit. */
#pragma once

#include <array>
#include <memory>
#include <optional>
#include <string>
#include "anyof.hpp"
#include "fallback.hpp"
#include "fan.hpp"
#include "gpio.hpp"
#include "tach.hpp"

using namespace std::string_literals;

namespace phosphor
{
namespace fan
{
namespace presence
{

struct ConfigPolicy;

struct ConfigSensors
{
    using Sensors = std::array<std::unique_ptr<PresenceSensor>, ${len(sensors)}>;

    static auto& get()
    {
        static const Sensors sensors =
        {
% for s in sensors:
            ${s.construct(loader, indent=indent +3)},
% endfor
        };
        return sensors;
    }
};

struct ConfigFans
{
    using Fans = std::array<Fan, ${len(fans)}>;

    static auto& get()
    {
        static const Fans fans =
        {
            {
% for f in fans:
                Fans::value_type{
                    "${f.name}"s,
                    "${f.path}"s,
                    std::nullopt
                },
% endfor
            }
        };
        return fans;
    }
};

struct ConfigPolicy
{
    using Policies = std::array<std::unique_ptr<RedundancyPolicy>, ${len(policies)}>;

    static auto& get()
    {
        static const Policies policies =
        {
% for p in policies:
            ${p.construct(loader, indent=indent +3)},
% endfor
        };
        return policies;
    }
};
} // namespace presence
} // namespace fan
} // namespace phosphor
