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

// SetVideoChatDefaultParticipantRequest represents TL type `setVideoChatDefaultParticipant#f1a672b3`.
type SetVideoChatDefaultParticipantRequest struct {
	// Chat identifier
	ChatID int64
	// Default group call participant identifier to join the video chats
	DefaultParticipantID MessageSenderClass
}

// SetVideoChatDefaultParticipantRequestTypeID is TL type id of SetVideoChatDefaultParticipantRequest.
const SetVideoChatDefaultParticipantRequestTypeID = 0xf1a672b3

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

func (s *SetVideoChatDefaultParticipantRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.DefaultParticipantID == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetVideoChatDefaultParticipantRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setVideoChatDefaultParticipant",
		ID:   SetVideoChatDefaultParticipantRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "DefaultParticipantID",
			SchemaName: "default_participant_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetVideoChatDefaultParticipantRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setVideoChatDefaultParticipant#f1a672b3 as nil")
	}
	b.PutID(SetVideoChatDefaultParticipantRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetVideoChatDefaultParticipantRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setVideoChatDefaultParticipant#f1a672b3 as nil")
	}
	b.PutInt53(s.ChatID)
	if s.DefaultParticipantID == nil {
		return fmt.Errorf("unable to encode setVideoChatDefaultParticipant#f1a672b3: field default_participant_id is nil")
	}
	if err := s.DefaultParticipantID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setVideoChatDefaultParticipant#f1a672b3: field default_participant_id: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetVideoChatDefaultParticipantRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setVideoChatDefaultParticipant#f1a672b3 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setVideoChatDefaultParticipant#f1a672b3: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := DecodeMessageSender(b)
		if err != nil {
			return fmt.Errorf("unable to decode setVideoChatDefaultParticipant#f1a672b3: field default_participant_id: %w", err)
		}
		s.DefaultParticipantID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetVideoChatDefaultParticipantRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setVideoChatDefaultParticipant#f1a672b3 as nil")
	}
	b.ObjStart()
	b.PutID("setVideoChatDefaultParticipant")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("default_participant_id")
	if s.DefaultParticipantID == nil {
		return fmt.Errorf("unable to encode setVideoChatDefaultParticipant#f1a672b3: field default_participant_id is nil")
	}
	if err := s.DefaultParticipantID.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setVideoChatDefaultParticipant#f1a672b3: field default_participant_id: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetVideoChatDefaultParticipantRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setVideoChatDefaultParticipant#f1a672b3 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setVideoChatDefaultParticipant"); err != nil {
				return fmt.Errorf("unable to decode setVideoChatDefaultParticipant#f1a672b3: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setVideoChatDefaultParticipant#f1a672b3: field chat_id: %w", err)
			}
			s.ChatID = value
		case "default_participant_id":
			value, err := DecodeTDLibJSONMessageSender(b)
			if err != nil {
				return fmt.Errorf("unable to decode setVideoChatDefaultParticipant#f1a672b3: field default_participant_id: %w", err)
			}
			s.DefaultParticipantID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetDefaultParticipantID returns value of DefaultParticipantID field.
func (s *SetVideoChatDefaultParticipantRequest) GetDefaultParticipantID() (value MessageSenderClass) {
	if s == nil {
		return
	}
	return s.DefaultParticipantID
}

// SetVideoChatDefaultParticipant invokes method setVideoChatDefaultParticipant#f1a672b3 returning error if any.
func (c *Client) SetVideoChatDefaultParticipant(ctx context.Context, request *SetVideoChatDefaultParticipantRequest) error {
	var ok Ok

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