import DataType from "../../../../parser/simple/DataType.js";
import { ReactiveUnaryExpression } from "../ReactiveUnaryExpression.js";

export class ReactiveNegate extends ReactiveUnaryExpression {
    /**
     *
     * @param {number} v
     * @returns {number}
     */
    transform(v) {
        return -v;
    }

    /**
     *
     * @return {ReactiveNegate}
     */
    clone() {
        const r = new ReactiveNegate();

        r.copy(this);

        return r;
    }

    equals(other) {
        return (other.isReactiveNegate === true) && super.equals(other);
    }

    toCode() {
        return `-${this.source.toCode()}`
    }


    /**
     *
     * @param {ReactiveExpression} source
     * @returns {ReactiveNegate}
     */
    static from(source) {
        const r = new ReactiveNegate();

        r.connect(source);

        return r;
    }
}

/**
 * @readonly
 * @type {DataType|string}
 */
ReactiveNegate.prototype.dataType = DataType.Number;

/**
 * @readonly
 * @type {boolean}
 */
ReactiveNegate.prototype.isArithmeticExpression = true;

/**
 * @readonly
 * @type {boolean}
 */
ReactiveNegate.prototype.isReactiveNegate = true;


