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

// AccountToggleConnectedBotPausedRequest represents TL type `account.toggleConnectedBotPaused#646e1097`.
// Pause or unpause a specific chat, temporarily disconnecting it from all business bots
// »¹.
//
// Links:
//  1. https://core.telegram.org/api/bots/connected-business-bots
//
// See https://core.telegram.org/method/account.toggleConnectedBotPaused for reference.
type AccountToggleConnectedBotPausedRequest struct {
	// The chat to pause
	Peer InputPeerClass
	// Whether to pause or unpause the chat
	Paused bool
}

// AccountToggleConnectedBotPausedRequestTypeID is TL type id of AccountToggleConnectedBotPausedRequest.
const AccountToggleConnectedBotPausedRequestTypeID = 0x646e1097

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

func (t *AccountToggleConnectedBotPausedRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.Peer == nil) {
		return false
	}
	if !(t.Paused == false) {
		return false
	}

	return true
}

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

// FillFrom fills AccountToggleConnectedBotPausedRequest from given interface.
func (t *AccountToggleConnectedBotPausedRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetPaused() (value bool)
}) {
	t.Peer = from.GetPeer()
	t.Paused = from.GetPaused()
}

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

// TypeName returns name of type in TL schema.
func (*AccountToggleConnectedBotPausedRequest) TypeName() string {
	return "account.toggleConnectedBotPaused"
}

// TypeInfo returns info about TL type.
func (t *AccountToggleConnectedBotPausedRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.toggleConnectedBotPaused",
		ID:   AccountToggleConnectedBotPausedRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Paused",
			SchemaName: "paused",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *AccountToggleConnectedBotPausedRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode account.toggleConnectedBotPaused#646e1097 as nil")
	}
	b.PutID(AccountToggleConnectedBotPausedRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *AccountToggleConnectedBotPausedRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode account.toggleConnectedBotPaused#646e1097 as nil")
	}
	if t.Peer == nil {
		return fmt.Errorf("unable to encode account.toggleConnectedBotPaused#646e1097: field peer is nil")
	}
	if err := t.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.toggleConnectedBotPaused#646e1097: field peer: %w", err)
	}
	b.PutBool(t.Paused)
	return nil
}

// Decode implements bin.Decoder.
func (t *AccountToggleConnectedBotPausedRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode account.toggleConnectedBotPaused#646e1097 to nil")
	}
	if err := b.ConsumeID(AccountToggleConnectedBotPausedRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode account.toggleConnectedBotPaused#646e1097: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *AccountToggleConnectedBotPausedRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode account.toggleConnectedBotPaused#646e1097 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode account.toggleConnectedBotPaused#646e1097: field peer: %w", err)
		}
		t.Peer = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode account.toggleConnectedBotPaused#646e1097: field paused: %w", err)
		}
		t.Paused = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (t *AccountToggleConnectedBotPausedRequest) GetPeer() (value InputPeerClass) {
	if t == nil {
		return
	}
	return t.Peer
}

// GetPaused returns value of Paused field.
func (t *AccountToggleConnectedBotPausedRequest) GetPaused() (value bool) {
	if t == nil {
		return
	}
	return t.Paused
}

// AccountToggleConnectedBotPaused invokes method account.toggleConnectedBotPaused#646e1097 returning error if any.
// Pause or unpause a specific chat, temporarily disconnecting it from all business bots
// »¹.
//
// Links:
//  1. https://core.telegram.org/api/bots/connected-business-bots
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/account.toggleConnectedBotPaused for reference.
func (c *Client) AccountToggleConnectedBotPaused(ctx context.Context, request *AccountToggleConnectedBotPausedRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
