#include "num.h"
#include <iostream>

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) {
    int new_val = this->value + other.value;
    return Num(new_val, this->modulo);
}

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

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

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

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

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

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

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

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

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

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

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