#include "dbc.hpp"
#include <iostream>

void dbc::log(const string &message) {
  std::cerr << "!!!!!!!!!!" << message << std::endl;
}

void dbc::sentinel(const string &message) {
  string err = fmt::format("[SENTINEL!] {}", message);
  dbc::log(err);
  throw dbc::SentinelError{err};
}

void dbc::pre(const string &message, bool test) {
  if(!test) {
    string err = fmt::format("[PRE!] {}", message);
    dbc::log(err);
    throw dbc::PreCondError{err};
  }
}

void dbc::pre(const string &message, std::function<bool()> tester) {
  dbc::pre(message, tester());
}

void dbc::post(const string &message, bool test) {
  if(!test) {
    string err = fmt::format("[POST!] {}", message);
    dbc::log(err);
    throw dbc::PostCondError{err};
  }
}

void dbc::post(const string &message, std::function<bool()> tester) {
  dbc::post(message, tester());
}

void dbc::check(bool test, const string &message) {
  if(!test) {
    string err = fmt::format("[CHECK!] {}\n", message);
    dbc::log(err);
    throw dbc::CheckError{err};
  }
}
