var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import { bufferToHexString } from '@iotize/common/byte-converter';
import { CodeError } from '@iotize/common/error';
var TapAuthError = /** @class */ (function (_super) {
    __extends(TapAuthError, _super);
    function TapAuthError(code, message, cause) {
        var _this = _super.call(this, message + (" (Error code '" + code + "')"), code) || this;
        _this.cause = cause;
        return _this;
    }
    TapAuthError.tapRequestError = function (params, err) {
        return new TapAuthError(TapAuthError.Code.TapRequestError, "Login failed. " + err.message, err);
    };
    TapAuthError.tooManyLoginFailedError = function (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);
    };
    TapAuthError.invalidCredentialsError = function (credentials, err) {
        return new TapAuthError(TapAuthError.Code.InvalidCredentials, "Login failed. Given username or password is not valid.", err);
    };
    return TapAuthError;
}(CodeError));
export { TapAuthError };
(function (TapAuthError) {
    var Code;
    (function (Code) {
        Code["InvalidServerProof"] = "TapAuthErrorInvalidServerProof";
        Code["ScramDisabled"] = "TapAuthErrorScramDisabled";
        Code["InvalidCredentials"] = "TapAuthErrorInvalidCredentials";
        Code["TooManyLoginAttempt"] = "TapAuthErrorTooManyLoginAttempt";
        Code["TapRequestError"] = "TapAuthErrorTapRequestError";
    })(Code = TapAuthError.Code || (TapAuthError.Code = {}));
    var InvalidServerKey = /** @class */ (function (_super) {
        __extends(InvalidServerKey, _super);
        function InvalidServerKey(deviceServerProof, expectedServerProof) {
            var _this = _super.call(this, Code.InvalidServerProof, "Login fail invalid server proof ('" + bufferToHexString(deviceServerProof) + "' != '" + bufferToHexString(expectedServerProof) + "') ") || this;
            _this.deviceServerProof = deviceServerProof;
            _this.expectedServerProof = expectedServerProof;
            return _this;
        }
        return InvalidServerKey;
    }(TapAuthError));
    TapAuthError.InvalidServerKey = InvalidServerKey;
})(TapAuthError || (TapAuthError = {}));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwLWF1dGgtZXJyb3IuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW90aXplL3RhcC9hdXRoLyIsInNvdXJjZXMiOlsibGliL3RhcC1hdXRoLWVycm9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7QUFBQSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUNsRSxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFLakQ7SUFBa0MsZ0NBQTRCO0lBeUIxRCxzQkFBWSxJQUF1QixFQUFFLE9BQWUsRUFBUyxLQUFhO1FBQTFFLFlBQ0ksa0JBQU0sT0FBTyxJQUFHLG1CQUFpQixJQUFJLE9BQUksQ0FBQSxFQUFFLElBQUksQ0FBQyxTQUNuRDtRQUY0RCxXQUFLLEdBQUwsS0FBSyxDQUFROztJQUUxRSxDQUFDO0lBekJNLDRCQUFlLEdBQXRCLFVBQXVCLE1BQVcsRUFBRSxHQUFVO1FBQzFDLE9BQU8sSUFBSSxZQUFZLENBQ25CLFlBQVksQ0FBQyxJQUFJLENBQUMsZUFBZSxFQUNqQyxtQkFBaUIsR0FBRyxDQUFDLE9BQVMsRUFDOUIsR0FBRyxDQUNOLENBQUM7SUFDTixDQUFDO0lBQ00sb0NBQXVCLEdBQTlCLFVBQStCLE1BQXdCLEVBQUUsR0FBMkI7UUFDaEYsT0FBTyxJQUFJLFlBQVksQ0FDbkIsWUFBWSxDQUFDLElBQUksQ0FBQyxtQkFBbUIsRUFDckMseUZBQ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