#include "num.h"

Num::Num(int value, int modulo) {
    if (modulo == 0) {
        this->value = value;
    } else {
        this->value = value % modulo;
        this->modulo = modulo;
    }
}

Num &Num::operator=(const Num &other) = default;

Num Num::operator+(const Num &other) {
    return Num(((int16_t) this->value + (int16_t) other.value), this->modulo);
}

Num Num::operator-(const Num &other) {
    return Num(((int16_t) this->value - (int16_t) other.value), this->modulo);
}

Num Num::operator*(const Num &other) {
    return Num(((int16_t) this->value * (int16_t) other.value), this->modulo);
}

Num Num::operator+(int num) {
    return Num(((int16_t) this->value + (int16_t) num), this->modulo);
}

Num Num::operator-(int num) {
    return Num(((int16_t) this->value - (int16_t) num), this->modulo);
}

Num Num::operator*(int num) {
    return Num(((int16_t) this->value * (int16_t) num), this->modulo);
}

Num &Num::operator+=(const Num &other) {
    this->value = ((int16_t) this->value + (int16_t) other.value);
    return *this;
}

Num &Num::operator-=(const Num &other) {
    this->value = ((int16_t) this->value - (int16_t) other.value);
    return *this;
}

Num &Num::operator*=(const Num &other) {
    this->value = ((int16_t) this->value * (int16_t) other.value);
    return *this;
}

Num &Num::operator*=(int num) {
    this->value = ((int16_t) this->value + (int16_t) num);
    return *this;
}

Num &Num::operator+=(int num) {
    this->value = ((int16_t) this->value + (int16_t) num);
    return *this;
}

Num &Num::operator-=(int num) {
    this->value = ((int16_t) this->value - (int16_t) num);
    return *this;
}