// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/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{}
)

// GroupCallInfo represents TL type `groupCallInfo#3533a0d4`.
type GroupCallInfo struct {
	// Identifier of the group call
	GroupCallID int32
	// Join response payload for tgcalls; empty if the call isn't joined
	JoinPayload string
}

// GroupCallInfoTypeID is TL type id of GroupCallInfo.
const GroupCallInfoTypeID = 0x3533a0d4

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

func (g *GroupCallInfo) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.GroupCallID == 0) {
		return false
	}
	if !(g.JoinPayload == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GroupCallInfo) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "groupCallInfo",
		ID:   GroupCallInfoTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "JoinPayload",
			SchemaName: "join_payload",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GroupCallInfo) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallInfo#3533a0d4 as nil")
	}
	b.PutID(GroupCallInfoTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GroupCallInfo) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallInfo#3533a0d4 as nil")
	}
	b.PutInt32(g.GroupCallID)
	b.PutString(g.JoinPayload)
	return nil
}

// Decode implements bin.Decoder.
func (g *GroupCallInfo) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallInfo#3533a0d4 to nil")
	}
	if err := b.ConsumeID(GroupCallInfoTypeID); err != nil {
		return fmt.Errorf("unable to decode groupCallInfo#3533a0d4: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GroupCallInfo) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallInfo#3533a0d4 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode groupCallInfo#3533a0d4: field group_call_id: %w", err)
		}
		g.GroupCallID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode groupCallInfo#3533a0d4: field join_payload: %w", err)
		}
		g.JoinPayload = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GroupCallInfo) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode groupCallInfo#3533a0d4 as nil")
	}
	b.ObjStart()
	b.PutID("groupCallInfo")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(g.GroupCallID)
	b.Comma()
	b.FieldStart("join_payload")
	b.PutString(g.JoinPayload)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GroupCallInfo) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode groupCallInfo#3533a0d4 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("groupCallInfo"); err != nil {
				return fmt.Errorf("unable to decode groupCallInfo#3533a0d4: %w", err)
			}
		case "group_call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode groupCallInfo#3533a0d4: field group_call_id: %w", err)
			}
			g.GroupCallID = value
		case "join_payload":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode groupCallInfo#3533a0d4: field join_payload: %w", err)
			}
			g.JoinPayload = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetGroupCallID returns value of GroupCallID field.
func (g *GroupCallInfo) GetGroupCallID() (value int32) {
	if g == nil {
		return
	}
	return g.GroupCallID
}

// GetJoinPayload returns value of JoinPayload field.
func (g *GroupCallInfo) GetJoinPayload() (value string) {
	if g == nil {
		return
	}
	return g.JoinPayload
}
