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

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

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

Num Num::operator+(const Num &other) {
    int new_number =  this->value + other.value;

    Num new_num(new_number % this->modulo, this->modulo);
    return new_num;
}

Num Num::operator*(const Num &other) {
    int64_t new_number = (int64_t) this->value * (int64_t) other.value;

    Num new_num(new_number % this->modulo, this->modulo);
    return new_num;
}

Num Num::operator-(const Num &other) {
    int64_t new_number = (int64_t) this->value - (int64_t) other.value;
    Num new_num(new_number % this->modulo, this->modulo);
    return new_num;
}
Num Num::operator-(int num) {
    int64_t new_number = (int64_t) this->value - (int64_t) num;
    Num new_num(new_number % this->modulo, this->modulo);
    return new_num;
}
Num Num::operator+(int num) {
    int64_t new_number = (int64_t) this->value + (int64_t) num;
    Num new_num(new_number % this->modulo, this->modulo);
    return new_num;
}

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

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

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

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

Num &Num::operator-=(const Num &other) {
    int64_t new_number = (int64_t) this->value - (int64_t) other.value;
    this->value = new_number % this->modulo;
    if (this->value < 0) {
        this->value = this->modulo + this->value;
    }
    return *this;
}
Num &Num::operator-=(int num) {
    int64_t new_number = (int64_t) this->value - (int64_t) num;
    this->value = new_number % this->modulo;
    if (this->value < 0) {
        this->value = this->modulo + this->value;
    }
    return *this;
}