#include <algorithm>
#include <vector>

#include "exploit.h"
#include "../util/db.h"

using namespace std;

/**
 * @brief Prints the ParameterizedQuality preconditions.
 */
void Exploit::print_preconds_q() {
    for_each(preconds_q.begin(), preconds_q.end(),
             [](ParameterizedQuality &q) { q.print(); });
}

/**
 * @brief Prints the ParameterizedTopology preconditions.
 */
void Exploit::print_preconds_t() {
    for_each(preconds_t.begin(), preconds_t.end(),
             [](ParameterizedTopology &t) { t.print(); });
}

/**
 * @brief Prints the ParameterizedQuality postconditions.
 */
void Exploit::print_postconds_q() {
    for_each(postconds_q.begin(), postconds_q.end(),
             [](PostconditionQ &q) {
        auto fact = std::get<1>(q);
        fact.print();
    });
}

/**
 * @brief Prints the ParameterizedTopology postconditions.
 */
void Exploit::print_postconds_t() {
    for_each(postconds_t.begin(), postconds_t.end(),
             [](PostconditionT &q) {
        auto fact = std::get<1>(q);
        fact.print();
    });
}

/**
 * @brief Constructor for Exploit
 * @details Initializes Exploit information with given pre- and postconditions.
 *
 * @param preId Exploit ID
 * @param preName Name of the Exploit
 * @param preNumParams Number of parameters for the Exploit
 * @param preconds A tuple of preconditions
 * @param postconds A tuple of postconditions
 */
Exploit::Exploit(int preId, string &preName, int preNumParams,
                 std::string &groupName,
                 std::tuple<std::vector<ParameterizedQuality>,
                            std::vector<ParameterizedTopology>>
                     preconds,
                 std::tuple<std::vector<PostconditionQ>,
                            std::vector<PostconditionT>>
                     postconds)
    : id(preId), name(preName), num_params(preNumParams), group(groupName),
      preconds_q(std::get<0>(preconds)), preconds_t(std::get<1>(preconds)),
      postconds_q(std::get<0>(postconds)), postconds_t(std::get<1>(postconds)) {}

Exploit::Exploit()
{
    
}

/**
 * @brief Prints the Exploit ID
 */
void Exploit::print_id() { cout << "Exploit " + to_string(this->id) << endl; }

/**
 * @brief Gets the ParameterizedQuality preconditions.
 */
vector<ParameterizedQuality> Exploit::precond_list_q() { return preconds_q; }

/**
 * @brief Gets the ParameterizedTopology preconditions.
 */
vector<ParameterizedTopology> Exploit::precond_list_t() { return preconds_t; }

/**
 * @brief Gets the ParameterizedQuality postconditions.
 */
vector<PostconditionQ> Exploit::postcond_list_q() { return postconds_q; }

/**
 * @brief Gets the ParameterizedTopology postconditions.
 */
vector<PostconditionT> Exploit::postcond_list_t() { return postconds_t; }
