import { bufferToHexString } from '@iotize/common/byte-converter';
import { CodeError } from '@iotize/common/error';
export class TapAuthError extends CodeError {
    constructor(code, message, cause) {
        super(message + ` (Error code '${code}')`, code);
        this.cause = cause;
    }
    static tapRequestError(params, err) {
        return new TapAuthError(TapAuthError.Code.TapRequestError, `Login failed. ${err.message}`, err);
    }
    static tooManyLoginFailedError(params, err) {
        return new TapAuthError(TapAuthError.Code.TooManyLoginAttempt, `Login failed due to too many login attempt. You must wait before trying to login again.`, err);
    }
    static invalidCredentialsError(credentials, err) {
        return new TapAuthError(TapAuthError.Code.InvalidCredentials, `Login failed. Given username or password is not valid.`, err);
    }
}
(function (TapAuthError) {
    let Code;
    (function (Code) {
        Code["InvalidServerProof"] = "TapAuthErrorInvalidServerProof";
        Code["ScramDisabled"] = "TapAuthErrorScramDisabled";
        Code["InvalidCredentials"] = "TapAuthErrorInvalidCredentials";
        Code["TooManyLoginAttempt"] = "TapAuthErrorTooManyLoginAttempt";
        Code["TapRequestError"] = "TapAuthErrorTapRequestError";
    })(Code = TapAuthError.Code || (TapAuthError.Code = {}));
    class InvalidServerKey extends TapAuthError {
        constructor(deviceServerProof, expectedServerProof) {
            super(Code.InvalidServerProof, `Login fail invalid server proof ('${bufferToHexString(deviceServerProof)}' != '${bufferToHexString(expectedServerProof)}') `);
            this.deviceServerProof = deviceServerProof;
            this.expectedServerProof = expectedServerProof;
        }
    }
    TapAuthError.InvalidServerKey = InvalidServerKey;
})(TapAuthError || (TapAuthError = {}));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwLWF1dGgtZXJyb3IuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW90aXplL3RhcC9hdXRoLyIsInNvdXJjZXMiOlsibGliL3RhcC1hdXRoLWVycm9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQ2xF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