package xerr

var message map[uint32]string

func init() {
	message = make(map[uint32]string)
	message = map[uint32]string{
		// General error
		SUCCESS: "Success",
		ERROR:   "Internal Server Error",
		// parameter error
		TooManyRequests:   "Too Many Requests",
		InvalidParams:     "Param Error",
		ErrorTokenEmpty:   "User token is empty",
		ErrorTokenInvalid: "User token is invalid",
		ErrorTokenExpire:  "User token is expired",
		SecretIsEmpty:     "Secret is empty",
		InvalidAccess:     "Invalid access",
		InvalidCiphertext: "Invalid ciphertext",
		SignatureMissing:  "Signature headers are missing",
		SignatureExpired:  "Signature is expired",
		SignatureInvalid:  "Signature is invalid",
		SignatureReplay:   "Signature nonce replay detected",
		// Database error
		DatabaseQueryError:   "Database query error",
		DatabaseUpdateError:  "Database update error",
		DatabaseInsertError:  "Database insert error",
		DatabaseDeletedError: "Database deleted error",

		// User error
		UserExist:                     "User already exists",
		UserNotExist:                  "User does not exist",
		UserPasswordError:             "User password error",
		UserDisabled:                  "User disabled",
		InsufficientBalance:           "Insufficient balance",
		StopRegister:                  "Stop register",
		TelegramNotBound:              "Telegram not bound ",
		UserNotBindOauth:              "User not bind oauth method",
		InviteCodeError:               "Invite code error",
		RegisterIPLimit:               "Too many registrations",
		EmailBindError:                "Email already bound",
		UserBindInviteCodeExist:       "Invite code already bound",
		FamilyMemberLimitExceeded:     "家庭成员数量已达上限",
		FamilyAlreadyBound:            "已绑定家庭组",
		FamilyCrossBindForbidden:      "禁止跨家庭组绑定",
		FamilyNotExist:                "家庭组不存在",
		FamilyStatusInvalid:           "家庭组状态无效",
		FamilyOwnerOperationForbidden: "家庭组所有者不允许此操作",
		WithdrawalStatusInvalid:       "提现状态无效",

		// Node error
		NodeExist:         "Node already exists",
		NodeNotExist:      "Node does not exist",
		NodeGroupExist:    "Node group already exists",
		NodeGroupNotExist: "Node group does not exist",
		NodeGroupNotEmpty: "Node group is not empty",

		//coupon error
		CouponNotExist:          "Coupon does not exist",
		CouponAlreadyUsed:       "Coupon has already been used",
		CouponNotApplicable:     "Coupon does not match the order or conditions",
		CouponInsufficientUsage: "Coupon has insufficient remaining uses",
		CouponExpired:           "Coupon is expired",

		// Subscribe
		SubscribeExpired:                "Subscribe is expired",
		SubscribeNotAvailable:           "Subscribe is not available",
		UserSubscribeExist:              "User has subscription",
		SubscribeIsUsedError:            "Subscribe is used",
		SingleSubscribeModeExceedsLimit: "Single subscribe mode exceeds limit",
		SubscribeQuotaLimit:             "Subscribe quota limit",
		SubscribeOutOfStock:             "Subscribe out of stock",
		SingleSubscribePlanMismatch:     "Single subscribe mode does not support switching subscription by purchase",
		SubscribeNewUserOnly:            "This plan is only available for new users within 24 hours of registration",

		// auth error
		VerifyCodeError: "Verify code error",

		// EnqueueError
		QueueEnqueueError: " Queue enqueue error",

		// System error
		DebugModeError: "Debug mode is enabled",

		GetAuthenticatorError:          "Unsupported login method",
		AuthenticatorNotSupportedError: "The authenticator does not support this method",

		TelephoneAreaCodeIsEmpty:           "Telephone area code is empty",
		TodaySendCountExceedsLimit:         "This account has reached the limit of sending times today",
		SmsNotEnabled:                      "Telephone login is not enabled",
		EmailNotEnabled:                    "Email function is not enabled yet",
		PasswordOrVerificationCodeRequired: "Password or verification code required",
		EmailExist:                         "Email already exists",
		TelephoneExist:                     "Telephone already exists",
		DeviceExist:                        "device exists",
		PasswordIsEmpty:                    "password is empty",
		TelephoneError:                     "telephone number error",
		DeviceNotExist:                     "Device does not exist",
		UseridNotMatch:                     "Userid not match",

		// Order error
		OrderNotExist:                 "Order does not exist",
		PaymentMethodNotFound:         "Payment method not found",
		OrderStatusError:              "Order status error",
		InsufficientOfPeriod:          "Insufficient number of period",
		OrderAlreadyRefunded:          "Order already refunded",
		OrderRefundNoSubscription:     "Refund target subscription not found",
		OrderRefundCommissionMismatch: "Refund commission source not found",

		// Permission error
		PermissionDenied: "Permission denied",
	}

}

func MapErrMsg(errCode uint32) string {
	if msg, ok := message[errCode]; ok {
		return msg
	} else {
		return "Internal Server Error"
	}
}

func IsCodeErr(errCode uint32) bool {
	if _, ok := message[errCode]; ok {
		return true
	} else {
		return false
	}
}
