import { bufferToHexString } from '@iotize/common/byte-converter';
import { CodeError } from '@iotize/common/error';
export class TapAuthError extends CodeError {
    constructor(code, message, cause) {
        super(message, 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwLWF1dGgtZXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9hdXRoL3NyYy9saWIvdGFwLWF1dGgtZXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDbEUsT0FBTyxF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