#include "dbc.hpp"

void dbc::log(const string &message) {
  fmt::print("{}\n", message);
}

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

void dbc::pre(const string &message, bool test) {
  if(!test) {
    string err = fmt::format("[PRE!] {}\n", message);
    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!] {}\n", message);
    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);
    fmt::println("{}", err);
    throw dbc::CheckError{err};
  }
}