import { Role } from "../model/role.model";
import { IsEmptyOrNullError, IsNullError } from "./customErrors";

export class CommonValidations {

    /**
     * Verifies if a given number is NaN. If so, throws TypeError.
     * @param numberToCheck The number to be verified.
     */
    throwTypeErrorIfNaN(numberToCheck: number) {
        if (Number.isNaN(numberToCheck)) throw TypeError('Value is not a number.');
    }

    /**
     * Verifies if a given string is empty or null. If so, throws IsEmptyError.
     * @param stringToCheck String to be checked.
     */
    throwIsEmptyOrNullErrorIfIs(stringToCheck: string) {
        if (stringToCheck == null || stringToCheck == "") throw new IsEmptyOrNullError('Value is empty.');
    }

    /**
     * Verifies if a given object is null. If so, throws IsNullError.
     * @param object Object to be checked.
     */
    throwIsNullErrorIfIs(object: string | Role) {
        if (object == null) throw new IsNullError('Value is null.')
    }
    
}