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

// UnpinAllMessageThreadMessagesRequest represents TL type `unpinAllMessageThreadMessages#b7c69f00`.
type UnpinAllMessageThreadMessagesRequest struct {
	// Identifier of the chat
	ChatID int64
	// Message thread identifier in which messages will be unpinned
	MessageThreadID int64
}

// UnpinAllMessageThreadMessagesRequestTypeID is TL type id of UnpinAllMessageThreadMessagesRequest.
const UnpinAllMessageThreadMessagesRequestTypeID = 0xb7c69f00

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

func (u *UnpinAllMessageThreadMessagesRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.ChatID == 0) {
		return false
	}
	if !(u.MessageThreadID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UnpinAllMessageThreadMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "unpinAllMessageThreadMessages",
		ID:   UnpinAllMessageThreadMessagesRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageThreadID",
			SchemaName: "message_thread_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UnpinAllMessageThreadMessagesRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode unpinAllMessageThreadMessages#b7c69f00 as nil")
	}
	b.PutID(UnpinAllMessageThreadMessagesRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UnpinAllMessageThreadMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode unpinAllMessageThreadMessages#b7c69f00 as nil")
	}
	b.PutInt53(u.ChatID)
	b.PutInt53(u.MessageThreadID)
	return nil
}

// Decode implements bin.Decoder.
func (u *UnpinAllMessageThreadMessagesRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode unpinAllMessageThreadMessages#b7c69f00 to nil")
	}
	if err := b.ConsumeID(UnpinAllMessageThreadMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode unpinAllMessageThreadMessages#b7c69f00: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UnpinAllMessageThreadMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode unpinAllMessageThreadMessages#b7c69f00 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode unpinAllMessageThreadMessages#b7c69f00: field chat_id: %w", err)
		}
		u.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode unpinAllMessageThreadMessages#b7c69f00: field message_thread_id: %w", err)
		}
		u.MessageThreadID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UnpinAllMessageThreadMessagesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode unpinAllMessageThreadMessages#b7c69f00 as nil")
	}
	b.ObjStart()
	b.PutID("unpinAllMessageThreadMessages")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(u.ChatID)
	b.Comma()
	b.FieldStart("message_thread_id")
	b.PutInt53(u.MessageThreadID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UnpinAllMessageThreadMessagesRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode unpinAllMessageThreadMessages#b7c69f00 to nil")
	}

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

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

// GetMessageThreadID returns value of MessageThreadID field.
func (u *UnpinAllMessageThreadMessagesRequest) GetMessageThreadID() (value int64) {
	if u == nil {
		return
	}
	return u.MessageThreadID
}

// UnpinAllMessageThreadMessages invokes method unpinAllMessageThreadMessages#b7c69f00 returning error if any.
func (c *Client) UnpinAllMessageThreadMessages(ctx context.Context, request *UnpinAllMessageThreadMessagesRequest) error {
	var ok Ok

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