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

// MessagesCheckedHistoryImportPeer represents TL type `messages.checkedHistoryImportPeer#a24de717`.
// Contains a confirmation text to be shown to the user, upon importing chat history,
// click here for more info »¹.
//
// Links:
//  1. https://core.telegram.org/api/import
//
// See https://core.telegram.org/constructor/messages.checkedHistoryImportPeer for reference.
type MessagesCheckedHistoryImportPeer struct {
	// A confirmation text to be shown to the user, upon importing chat history »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/import
	ConfirmText string
}

// MessagesCheckedHistoryImportPeerTypeID is TL type id of MessagesCheckedHistoryImportPeer.
const MessagesCheckedHistoryImportPeerTypeID = 0xa24de717

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

func (c *MessagesCheckedHistoryImportPeer) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.ConfirmText == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesCheckedHistoryImportPeer from given interface.
func (c *MessagesCheckedHistoryImportPeer) FillFrom(from interface {
	GetConfirmText() (value string)
}) {
	c.ConfirmText = from.GetConfirmText()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesCheckedHistoryImportPeer) TypeName() string {
	return "messages.checkedHistoryImportPeer"
}

// TypeInfo returns info about TL type.
func (c *MessagesCheckedHistoryImportPeer) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.checkedHistoryImportPeer",
		ID:   MessagesCheckedHistoryImportPeerTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ConfirmText",
			SchemaName: "confirm_text",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *MessagesCheckedHistoryImportPeer) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode messages.checkedHistoryImportPeer#a24de717 as nil")
	}
	b.PutID(MessagesCheckedHistoryImportPeerTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *MessagesCheckedHistoryImportPeer) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode messages.checkedHistoryImportPeer#a24de717 as nil")
	}
	b.PutString(c.ConfirmText)
	return nil
}

// Decode implements bin.Decoder.
func (c *MessagesCheckedHistoryImportPeer) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode messages.checkedHistoryImportPeer#a24de717 to nil")
	}
	if err := b.ConsumeID(MessagesCheckedHistoryImportPeerTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.checkedHistoryImportPeer#a24de717: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *MessagesCheckedHistoryImportPeer) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode messages.checkedHistoryImportPeer#a24de717 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.checkedHistoryImportPeer#a24de717: field confirm_text: %w", err)
		}
		c.ConfirmText = value
	}
	return nil
}

// GetConfirmText returns value of ConfirmText field.
func (c *MessagesCheckedHistoryImportPeer) GetConfirmText() (value string) {
	if c == nil {
		return
	}
	return c.ConfirmText
}
