
#include <cmath>
#include <complex>
#include <algorithm>
#include <iostream>

#include "hark-lib/node/AND.h"

namespace hark
{
namespace node
{
    AND::AND():
        NodeDef("AND")
    {
        *this
            << Terminal::in("INPUT1")
            << Terminal::in("INPUT2")
            << Terminal::in("INPUT3").def(true)
            << Terminal::in("INPUT4").def(true)
            << Terminal::in("INPUT5").def(true)
            << Terminal::in("INPUT6").def(true)
            << Terminal::in("INPUT7").def(true)
            << Terminal::in("INPUT8").def(true)
            << Terminal::in("INPUT9").def(true)
            << Terminal::in("INPUT10").def(true)
            << Terminal::in("INPUT11").def(true)
            << Terminal::in("INPUT12").def(true)
            << Terminal::in("INPUT13").def(true)
            << Terminal::in("INPUT14").def(true)
            << Terminal::in("INPUT15").def(true)
            << Terminal::in("INPUT16").def(true)
            >> Terminal::out("OUTPUT");
    }

    void
    AND::reset()
    {
    }

    void
    AND::initialize(InputDataBundle &input)
    {
    }

    bool
    AND::operator () (size_t count, InputDataBundle &input, OutputDataBundle &output)
    {
        const auto &input1 = input["INPUT1"].last().as<bool>();
        const auto &input2 = input["INPUT2"].last().as<bool>();
        const auto &input3 = input["INPUT3"].last().as<bool>();
        const auto &input4 = input["INPUT4"].last().as<bool>();
        const auto &input5 = input["INPUT5"].last().as<bool>();
        const auto &input6 = input["INPUT6"].last().as<bool>();
        const auto &input7 = input["INPUT7"].last().as<bool>();
        const auto &input8 = input["INPUT8"].last().as<bool>();
        const auto &input9 = input["INPUT9"].last().as<bool>();
        const auto &input10 = input["INPUT10"].last().as<bool>();
        const auto &input11 = input["INPUT11"].last().as<bool>();
        const auto &input12 = input["INPUT12"].last().as<bool>();
        const auto &input13 = input["INPUT13"].last().as<bool>();
        const auto &input14 = input["INPUT14"].last().as<bool>();
        const auto &input15 = input["INPUT15"].last().as<bool>();
        const auto &input16 = input["INPUT16"].last().as<bool>();

#ifdef DEBUG
        ptime start_time;
        ptime end_time;
        start_time = microsec_clock::local_time();
#endif

        output["OUTPUT"].push(data::create<bool>(
            input1  && input2  && input3  && input4  &&
            input5  && input6  && input7  && input8  &&
            input9  && input10 && input11 && input12 &&
            input13 && input14 && input15 && input16));

#ifdef DEBUG
        end_time = microsec_clock::local_time();
        std::cout << end_time - start_time << std::endl;
#endif

        return true;
    }
}
}

/* end of file */
