// 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{}
)

// Pong represents TL type `pong#347773c5`.
type Pong struct {
	// MsgID field of Pong.
	MsgID int64
	// PingID field of Pong.
	PingID int64
}

// PongTypeID is TL type id of Pong.
const PongTypeID = 0x347773c5

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

func (p *Pong) Zero() bool {
	if p == nil {
		return true
	}
	if !(p.MsgID == 0) {
		return false
	}
	if !(p.PingID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (p *Pong) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "pong",
		ID:   PongTypeID,
	}
	if p == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
		},
		{
			Name:       "PingID",
			SchemaName: "ping_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (p *Pong) Encode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pong#347773c5 as nil")
	}
	b.PutID(PongTypeID)
	return p.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (p *Pong) EncodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't encode pong#347773c5 as nil")
	}
	b.PutLong(p.MsgID)
	b.PutLong(p.PingID)
	return nil
}

// Decode implements bin.Decoder.
func (p *Pong) Decode(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pong#347773c5 to nil")
	}
	if err := b.ConsumeID(PongTypeID); err != nil {
		return fmt.Errorf("unable to decode pong#347773c5: %w", err)
	}
	return p.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (p *Pong) DecodeBare(b *bin.Buffer) error {
	if p == nil {
		return fmt.Errorf("can't decode pong#347773c5 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode pong#347773c5: field msg_id: %w", err)
		}
		p.MsgID = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode pong#347773c5: field ping_id: %w", err)
		}
		p.PingID = value
	}
	return nil
}

// GetMsgID returns value of MsgID field.
func (p *Pong) GetMsgID() (value int64) {
	if p == nil {
		return
	}
	return p.MsgID
}

// GetPingID returns value of PingID field.
func (p *Pong) GetPingID() (value int64) {
	if p == nil {
		return
	}
	return p.PingID
}
