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

// DeclineGroupCallInvitationRequest represents TL type `declineGroupCallInvitation#6de7fa11`.
type DeclineGroupCallInvitationRequest struct {
	// Identifier of the chat with the message
	ChatID int64
	// Identifier of the message of the type messageGroupCall
	MessageID int64
}

// DeclineGroupCallInvitationRequestTypeID is TL type id of DeclineGroupCallInvitationRequest.
const DeclineGroupCallInvitationRequestTypeID = 0x6de7fa11

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

func (d *DeclineGroupCallInvitationRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.ChatID == 0) {
		return false
	}
	if !(d.MessageID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (d *DeclineGroupCallInvitationRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "declineGroupCallInvitation",
		ID:   DeclineGroupCallInvitationRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *DeclineGroupCallInvitationRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode declineGroupCallInvitation#6de7fa11 as nil")
	}
	b.PutID(DeclineGroupCallInvitationRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeclineGroupCallInvitationRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode declineGroupCallInvitation#6de7fa11 as nil")
	}
	b.PutInt53(d.ChatID)
	b.PutInt53(d.MessageID)
	return nil
}

// Decode implements bin.Decoder.
func (d *DeclineGroupCallInvitationRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode declineGroupCallInvitation#6de7fa11 to nil")
	}
	if err := b.ConsumeID(DeclineGroupCallInvitationRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode declineGroupCallInvitation#6de7fa11: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *DeclineGroupCallInvitationRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode declineGroupCallInvitation#6de7fa11 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode declineGroupCallInvitation#6de7fa11: field chat_id: %w", err)
		}
		d.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode declineGroupCallInvitation#6de7fa11: field message_id: %w", err)
		}
		d.MessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeclineGroupCallInvitationRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode declineGroupCallInvitation#6de7fa11 as nil")
	}
	b.ObjStart()
	b.PutID("declineGroupCallInvitation")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(d.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(d.MessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeclineGroupCallInvitationRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode declineGroupCallInvitation#6de7fa11 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("declineGroupCallInvitation"); err != nil {
				return fmt.Errorf("unable to decode declineGroupCallInvitation#6de7fa11: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode declineGroupCallInvitation#6de7fa11: field chat_id: %w", err)
			}
			d.ChatID = value
		case "message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode declineGroupCallInvitation#6de7fa11: field message_id: %w", err)
			}
			d.MessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (d *DeclineGroupCallInvitationRequest) GetChatID() (value int64) {
	if d == nil {
		return
	}
	return d.ChatID
}

// GetMessageID returns value of MessageID field.
func (d *DeclineGroupCallInvitationRequest) GetMessageID() (value int64) {
	if d == nil {
		return
	}
	return d.MessageID
}

// DeclineGroupCallInvitation invokes method declineGroupCallInvitation#6de7fa11 returning error if any.
func (c *Client) DeclineGroupCallInvitation(ctx context.Context, request *DeclineGroupCallInvitationRequest) error {
	var ok Ok

	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
