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

// BotsGetAccessSettingsRequest represents TL type `bots.getAccessSettings#213853a3`.
//
// See https://core.telegram.org/method/bots.getAccessSettings for reference.
type BotsGetAccessSettingsRequest struct {
	// Bot field of BotsGetAccessSettingsRequest.
	Bot InputUserClass
}

// BotsGetAccessSettingsRequestTypeID is TL type id of BotsGetAccessSettingsRequest.
const BotsGetAccessSettingsRequestTypeID = 0x213853a3

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

func (g *BotsGetAccessSettingsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Bot == nil) {
		return false
	}

	return true
}

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

// FillFrom fills BotsGetAccessSettingsRequest from given interface.
func (g *BotsGetAccessSettingsRequest) FillFrom(from interface {
	GetBot() (value InputUserClass)
}) {
	g.Bot = from.GetBot()
}

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

// TypeName returns name of type in TL schema.
func (*BotsGetAccessSettingsRequest) TypeName() string {
	return "bots.getAccessSettings"
}

// TypeInfo returns info about TL type.
func (g *BotsGetAccessSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "bots.getAccessSettings",
		ID:   BotsGetAccessSettingsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *BotsGetAccessSettingsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode bots.getAccessSettings#213853a3 as nil")
	}
	b.PutID(BotsGetAccessSettingsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *BotsGetAccessSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode bots.getAccessSettings#213853a3 as nil")
	}
	if g.Bot == nil {
		return fmt.Errorf("unable to encode bots.getAccessSettings#213853a3: field bot is nil")
	}
	if err := g.Bot.Encode(b); err != nil {
		return fmt.Errorf("unable to encode bots.getAccessSettings#213853a3: field bot: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *BotsGetAccessSettingsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode bots.getAccessSettings#213853a3 to nil")
	}
	if err := b.ConsumeID(BotsGetAccessSettingsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode bots.getAccessSettings#213853a3: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *BotsGetAccessSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode bots.getAccessSettings#213853a3 to nil")
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode bots.getAccessSettings#213853a3: field bot: %w", err)
		}
		g.Bot = value
	}
	return nil
}

// GetBot returns value of Bot field.
func (g *BotsGetAccessSettingsRequest) GetBot() (value InputUserClass) {
	if g == nil {
		return
	}
	return g.Bot
}

// BotsGetAccessSettings invokes method bots.getAccessSettings#213853a3 returning error if any.
//
// See https://core.telegram.org/method/bots.getAccessSettings for reference.
func (c *Client) BotsGetAccessSettings(ctx context.Context, bot InputUserClass) (*BotsAccessSettings, error) {
	var result BotsAccessSettings

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