// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// UsersSuggestBirthdayRequest represents TL type `users.suggestBirthday#fc533372`.
//
// See https://core.telegram.org/method/users.suggestBirthday for reference.
type UsersSuggestBirthdayRequest struct {
	// ID field of UsersSuggestBirthdayRequest.
	ID InputUserClass
	// Birthday field of UsersSuggestBirthdayRequest.
	Birthday Birthday
}

// UsersSuggestBirthdayRequestTypeID is TL type id of UsersSuggestBirthdayRequest.
const UsersSuggestBirthdayRequestTypeID = 0xfc533372

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

func (s *UsersSuggestBirthdayRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ID == nil) {
		return false
	}
	if !(s.Birthday.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills UsersSuggestBirthdayRequest from given interface.
func (s *UsersSuggestBirthdayRequest) FillFrom(from interface {
	GetID() (value InputUserClass)
	GetBirthday() (value Birthday)
}) {
	s.ID = from.GetID()
	s.Birthday = from.GetBirthday()
}

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

// TypeName returns name of type in TL schema.
func (*UsersSuggestBirthdayRequest) TypeName() string {
	return "users.suggestBirthday"
}

// TypeInfo returns info about TL type.
func (s *UsersSuggestBirthdayRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "users.suggestBirthday",
		ID:   UsersSuggestBirthdayRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Birthday",
			SchemaName: "birthday",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *UsersSuggestBirthdayRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode users.suggestBirthday#fc533372 as nil")
	}
	b.PutID(UsersSuggestBirthdayRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *UsersSuggestBirthdayRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode users.suggestBirthday#fc533372 as nil")
	}
	if s.ID == nil {
		return fmt.Errorf("unable to encode users.suggestBirthday#fc533372: field id is nil")
	}
	if err := s.ID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode users.suggestBirthday#fc533372: field id: %w", err)
	}
	if err := s.Birthday.Encode(b); err != nil {
		return fmt.Errorf("unable to encode users.suggestBirthday#fc533372: field birthday: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *UsersSuggestBirthdayRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode users.suggestBirthday#fc533372 to nil")
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode users.suggestBirthday#fc533372: field id: %w", err)
		}
		s.ID = value
	}
	{
		if err := s.Birthday.Decode(b); err != nil {
			return fmt.Errorf("unable to decode users.suggestBirthday#fc533372: field birthday: %w", err)
		}
	}
	return nil
}

// GetID returns value of ID field.
func (s *UsersSuggestBirthdayRequest) GetID() (value InputUserClass) {
	if s == nil {
		return
	}
	return s.ID
}

// GetBirthday returns value of Birthday field.
func (s *UsersSuggestBirthdayRequest) GetBirthday() (value Birthday) {
	if s == nil {
		return
	}
	return s.Birthday
}

// UsersSuggestBirthday invokes method users.suggestBirthday#fc533372 returning error if any.
//
// See https://core.telegram.org/method/users.suggestBirthday for reference.
func (c *Client) UsersSuggestBirthday(ctx context.Context, request *UsersSuggestBirthdayRequest) (UpdatesClass, error) {
	var result UpdatesBox

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