// Code generated by gotdgen, DO NOT EDIT.

package mt

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// ServerDHInnerData represents TL type `server_DH_inner_data#b5890dba`.
type ServerDHInnerData struct {
	// Nonce field of ServerDHInnerData.
	Nonce bin.Int128
	// ServerNonce field of ServerDHInnerData.
	ServerNonce bin.Int128
	// G field of ServerDHInnerData.
	G int
	// DhPrime field of ServerDHInnerData.
	DhPrime []byte
	// GA field of ServerDHInnerData.
	GA []byte
	// ServerTime field of ServerDHInnerData.
	ServerTime int
}

// ServerDHInnerDataTypeID is TL type id of ServerDHInnerData.
const ServerDHInnerDataTypeID = 0xb5890dba

// Ensuring interfaces in compile-time for ServerDHInnerData.
var (
	_ bin.Encoder     = &ServerDHInnerData{}
	_ bin.Decoder     = &ServerDHInnerData{}
	_ bin.BareEncoder = &ServerDHInnerData{}
	_ bin.BareDecoder = &ServerDHInnerData{}
)

func (s *ServerDHInnerData) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Nonce == bin.Int128{}) {
		return false
	}
	if !(s.ServerNonce == bin.Int128{}) {
		return false
	}
	if !(s.G == 0) {
		return false
	}
	if !(s.DhPrime == nil) {
		return false
	}
	if !(s.GA == nil) {
		return false
	}
	if !(s.ServerTime == 0) {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func (s *ServerDHInnerData) String() string {
	if s == nil {
		return "ServerDHInnerData(nil)"
	}
	type Alias ServerDHInnerData
	return fmt.Sprintf("ServerDHInnerData%+v", Alias(*s))
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ServerDHInnerData) TypeID() uint32 {
	return ServerDHInnerDataTypeID
}

// TypeName returns name of type in TL schema.
func (*ServerDHInnerData) TypeName() string {
	return "server_DH_inner_data"
}

// TypeInfo returns info about TL type.
func (s *ServerDHInnerData) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "server_DH_inner_data",
		ID:   ServerDHInnerDataTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Nonce",
			SchemaName: "nonce",
		},
		{
			Name:       "ServerNonce",
			SchemaName: "server_nonce",
		},
		{
			Name:       "G",
			SchemaName: "g",
		},
		{
			Name:       "DhPrime",
			SchemaName: "dh_prime",
		},
		{
			Name:       "GA",
			SchemaName: "g_a",
		},
		{
			Name:       "ServerTime",
			SchemaName: "server_time",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *ServerDHInnerData) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode server_DH_inner_data#b5890dba as nil")
	}
	b.PutID(ServerDHInnerDataTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *ServerDHInnerData) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode server_DH_inner_data#b5890dba as nil")
	}
	b.PutInt128(s.Nonce)
	b.PutInt128(s.ServerNonce)
	b.PutInt(s.G)
	b.PutBytes(s.DhPrime)
	b.PutBytes(s.GA)
	b.PutInt(s.ServerTime)
	return nil
}

// Decode implements bin.Decoder.
func (s *ServerDHInnerData) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode server_DH_inner_data#b5890dba to nil")
	}
	if err := b.ConsumeID(ServerDHInnerDataTypeID); err != nil {
		return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *ServerDHInnerData) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode server_DH_inner_data#b5890dba to nil")
	}
	{
		value, err := b.Int128()
		if err != nil {
			return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: field nonce: %w", err)
		}
		s.Nonce = value
	}
	{
		value, err := b.Int128()
		if err != nil {
			return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: field server_nonce: %w", err)
		}
		s.ServerNonce = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: field g: %w", err)
		}
		s.G = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: field dh_prime: %w", err)
		}
		s.DhPrime = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: field g_a: %w", err)
		}
		s.GA = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode server_DH_inner_data#b5890dba: field server_time: %w", err)
		}
		s.ServerTime = value
	}
	return nil
}

// GetNonce returns value of Nonce field.
func (s *ServerDHInnerData) GetNonce() (value bin.Int128) {
	if s == nil {
		return
	}
	return s.Nonce
}

// GetServerNonce returns value of ServerNonce field.
func (s *ServerDHInnerData) GetServerNonce() (value bin.Int128) {
	if s == nil {
		return
	}
	return s.ServerNonce
}

// GetG returns value of G field.
func (s *ServerDHInnerData) GetG() (value int) {
	if s == nil {
		return
	}
	return s.G
}

// GetDhPrime returns value of DhPrime field.
func (s *ServerDHInnerData) GetDhPrime() (value []byte) {
	if s == nil {
		return
	}
	return s.DhPrime
}

// GetGA returns value of GA field.
func (s *ServerDHInnerData) GetGA() (value []byte) {
	if s == nil {
		return
	}
	return s.GA
}

// GetServerTime returns value of ServerTime field.
func (s *ServerDHInnerData) GetServerTime() (value int) {
	if s == nil {
		return
	}
	return s.ServerTime
}
