package mtproto

import (
	

	

	
	
)

type badMessageError struct {
	Code    int
	NewSalt int64
}

const (
	codeMessageIDTooLow     = 16
	codeMessageIDTooHigh    = 17
	codeIncorrectServerSalt = 48
)

func ( badMessageError) () string {
	 := map[int]string{
		codeMessageIDTooLow:     "msg_id too low",
		codeMessageIDTooHigh:    "msg_id too high",
		codeIncorrectServerSalt: "incorrect server salt",

		18: "incorrect two lower order msg_id bits",
		19: "container msg_id is the same as msg_id of a previously received message",
		20: "message too old",
		32: "msg_seqno too low",
		33: "msg_seqno too high",
		34: "even msg_seqno expected, but odd received",
		35: "odd msg_seqno expected, but even received",
	}[.Code]
	if  == "" {
		return fmt.Sprintf("bad msg error code %d", .Code)
	}
	return 
}

func ( *Conn) ( *bin.Buffer) error {
	,  := .PeekID()
	if  != nil {
		return 
	}
	switch  {
	case mt.BadMsgNotificationTypeID:
		var  mt.BadMsgNotification
		if  := .Decode();  != nil {
			return 
		}

		.rpc.NotifyError(.BadMsgID, &badMessageError{Code: .ErrorCode})
		return nil
	case mt.BadServerSaltTypeID:
		var  mt.BadServerSalt
		if  := .Decode();  != nil {
			return 
		}

		.rpc.NotifyError(.BadMsgID, &badMessageError{Code: .ErrorCode, NewSalt: .NewServerSalt})
		return nil
	default:
		return errors.Errorf("unknown type id 0x%d", )
	}
}