// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// SavedDialog represents TL type `savedDialog#bd87cb6c`.
// Represents a saved dialog »¹.
//
// Links:
//  1. https://core.telegram.org/api/saved-messages
//
// See https://core.telegram.org/constructor/savedDialog for reference.
type SavedDialog struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Is the dialog pinned
	Pinned bool
	// The dialog
	Peer PeerClass
	// The latest message ID
	TopMessage int
}

// SavedDialogTypeID is TL type id of SavedDialog.
const SavedDialogTypeID = 0xbd87cb6c

// construct implements constructor of SavedDialogClass.
func ( SavedDialog) () SavedDialogClass { return & }

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

	_ SavedDialogClass = &SavedDialog{}
)

func ( *SavedDialog) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Pinned == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.TopMessage == 0) {
		return false
	}

	return true
}

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

// FillFrom fills SavedDialog from given interface.
func ( *SavedDialog) ( interface {
	() ( bool)
	() ( PeerClass)
	() ( int)
}) {
	.Pinned = .()
	.Peer = .()
	.TopMessage = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *SavedDialog) () tdp.Type {
	 := tdp.Type{
		Name: "savedDialog",
		ID:   SavedDialogTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Pinned",
			SchemaName: "pinned",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "TopMessage",
			SchemaName: "top_message",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SavedDialog) () {
	if !(.Pinned == false) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *SavedDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode savedDialog#bd87cb6c as nil")
	}
	.PutID(SavedDialogTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SavedDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode savedDialog#bd87cb6c as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode savedDialog#bd87cb6c: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode savedDialog#bd87cb6c: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode savedDialog#bd87cb6c: field peer: %w", )
	}
	.PutInt(.TopMessage)
	return nil
}

// Decode implements bin.Decoder.
func ( *SavedDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode savedDialog#bd87cb6c to nil")
	}
	if  := .ConsumeID(SavedDialogTypeID);  != nil {
		return fmt.Errorf("unable to decode savedDialog#bd87cb6c: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *SavedDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode savedDialog#bd87cb6c to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode savedDialog#bd87cb6c: field flags: %w", )
		}
	}
	.Pinned = .Flags.Has(2)
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode savedDialog#bd87cb6c: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode savedDialog#bd87cb6c: field top_message: %w", )
		}
		.TopMessage = 
	}
	return nil
}

// SetPinned sets value of Pinned conditional field.
func ( *SavedDialog) ( bool) {
	if  {
		.Flags.Set(2)
		.Pinned = true
	} else {
		.Flags.Unset(2)
		.Pinned = false
	}
}

// GetPinned returns value of Pinned conditional field.
func ( *SavedDialog) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetPeer returns value of Peer field.
func ( *SavedDialog) () ( PeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// GetTopMessage returns value of TopMessage field.
func ( *SavedDialog) () ( int) {
	if  == nil {
		return
	}
	return .TopMessage
}

// MonoForumDialog represents TL type `monoForumDialog#64407ea7`.
// Represents a monoforum topic »¹.
//
// Links:
//  1. https://core.telegram.org/api/monoforum
//
// See https://core.telegram.org/constructor/monoForumDialog for reference.
type MonoForumDialog struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this topic has a manually set (with messages.markDialogUnread¹) unread mark.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.markDialogUnread
	UnreadMark bool
	// If set, an admin has exempted this peer from payment to send messages using account
	// toggleNoPaidMessagesException¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/account.toggleNoPaidMessagesException
	NopaidMessagesException bool
	// The peer associated to the topic, AKA the topic ID.
	Peer PeerClass
	// The latest message ID
	TopMessage int
	// Position up to which all incoming messages are read.
	ReadInboxMaxID int
	// Position up to which all outgoing messages are read.
	ReadOutboxMaxID int
	// Number of unread messages.
	UnreadCount int
	// Number of unread reactions.
	UnreadReactionsCount int
	// A pending message draft¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/drafts
	//
	// Use SetDraft and GetDraft helpers.
	Draft DraftMessageClass
}

// MonoForumDialogTypeID is TL type id of MonoForumDialog.
const MonoForumDialogTypeID = 0x64407ea7

// construct implements constructor of SavedDialogClass.
func ( MonoForumDialog) () SavedDialogClass { return & }

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

	_ SavedDialogClass = &MonoForumDialog{}
)

func ( *MonoForumDialog) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.UnreadMark == false) {
		return false
	}
	if !(.NopaidMessagesException == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.TopMessage == 0) {
		return false
	}
	if !(.ReadInboxMaxID == 0) {
		return false
	}
	if !(.ReadOutboxMaxID == 0) {
		return false
	}
	if !(.UnreadCount == 0) {
		return false
	}
	if !(.UnreadReactionsCount == 0) {
		return false
	}
	if !(.Draft == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MonoForumDialog from given interface.
func ( *MonoForumDialog) ( interface {
	() ( bool)
	() ( bool)
	() ( PeerClass)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( DraftMessageClass,  bool)
}) {
	.UnreadMark = .()
	.NopaidMessagesException = .()
	.Peer = .()
	.TopMessage = .()
	.ReadInboxMaxID = .()
	.ReadOutboxMaxID = .()
	.UnreadCount = .()
	.UnreadReactionsCount = .()
	if ,  := .();  {
		.Draft = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *MonoForumDialog) () tdp.Type {
	 := tdp.Type{
		Name: "monoForumDialog",
		ID:   MonoForumDialogTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UnreadMark",
			SchemaName: "unread_mark",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "NopaidMessagesException",
			SchemaName: "nopaid_messages_exception",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "TopMessage",
			SchemaName: "top_message",
		},
		{
			Name:       "ReadInboxMaxID",
			SchemaName: "read_inbox_max_id",
		},
		{
			Name:       "ReadOutboxMaxID",
			SchemaName: "read_outbox_max_id",
		},
		{
			Name:       "UnreadCount",
			SchemaName: "unread_count",
		},
		{
			Name:       "UnreadReactionsCount",
			SchemaName: "unread_reactions_count",
		},
		{
			Name:       "Draft",
			SchemaName: "draft",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MonoForumDialog) () {
	if !(.UnreadMark == false) {
		.Flags.Set(3)
	}
	if !(.NopaidMessagesException == false) {
		.Flags.Set(4)
	}
	if !(.Draft == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *MonoForumDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode monoForumDialog#64407ea7 as nil")
	}
	.PutID(MonoForumDialogTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MonoForumDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode monoForumDialog#64407ea7 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode monoForumDialog#64407ea7: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode monoForumDialog#64407ea7: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode monoForumDialog#64407ea7: field peer: %w", )
	}
	.PutInt(.TopMessage)
	.PutInt(.ReadInboxMaxID)
	.PutInt(.ReadOutboxMaxID)
	.PutInt(.UnreadCount)
	.PutInt(.UnreadReactionsCount)
	if .Flags.Has(1) {
		if .Draft == nil {
			return fmt.Errorf("unable to encode monoForumDialog#64407ea7: field draft is nil")
		}
		if  := .Draft.Encode();  != nil {
			return fmt.Errorf("unable to encode monoForumDialog#64407ea7: field draft: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *MonoForumDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode monoForumDialog#64407ea7 to nil")
	}
	if  := .ConsumeID(MonoForumDialogTypeID);  != nil {
		return fmt.Errorf("unable to decode monoForumDialog#64407ea7: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MonoForumDialog) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode monoForumDialog#64407ea7 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field flags: %w", )
		}
	}
	.UnreadMark = .Flags.Has(3)
	.NopaidMessagesException = .Flags.Has(4)
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field top_message: %w", )
		}
		.TopMessage = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field read_inbox_max_id: %w", )
		}
		.ReadInboxMaxID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field read_outbox_max_id: %w", )
		}
		.ReadOutboxMaxID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field unread_count: %w", )
		}
		.UnreadCount = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field unread_reactions_count: %w", )
		}
		.UnreadReactionsCount = 
	}
	if .Flags.Has(1) {
		,  := DecodeDraftMessage()
		if  != nil {
			return fmt.Errorf("unable to decode monoForumDialog#64407ea7: field draft: %w", )
		}
		.Draft = 
	}
	return nil
}

// SetUnreadMark sets value of UnreadMark conditional field.
func ( *MonoForumDialog) ( bool) {
	if  {
		.Flags.Set(3)
		.UnreadMark = true
	} else {
		.Flags.Unset(3)
		.UnreadMark = false
	}
}

// GetUnreadMark returns value of UnreadMark conditional field.
func ( *MonoForumDialog) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetNopaidMessagesException sets value of NopaidMessagesException conditional field.
func ( *MonoForumDialog) ( bool) {
	if  {
		.Flags.Set(4)
		.NopaidMessagesException = true
	} else {
		.Flags.Unset(4)
		.NopaidMessagesException = false
	}
}

// GetNopaidMessagesException returns value of NopaidMessagesException conditional field.
func ( *MonoForumDialog) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// GetPeer returns value of Peer field.
func ( *MonoForumDialog) () ( PeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// GetTopMessage returns value of TopMessage field.
func ( *MonoForumDialog) () ( int) {
	if  == nil {
		return
	}
	return .TopMessage
}

// GetReadInboxMaxID returns value of ReadInboxMaxID field.
func ( *MonoForumDialog) () ( int) {
	if  == nil {
		return
	}
	return .ReadInboxMaxID
}

// GetReadOutboxMaxID returns value of ReadOutboxMaxID field.
func ( *MonoForumDialog) () ( int) {
	if  == nil {
		return
	}
	return .ReadOutboxMaxID
}

// GetUnreadCount returns value of UnreadCount field.
func ( *MonoForumDialog) () ( int) {
	if  == nil {
		return
	}
	return .UnreadCount
}

// GetUnreadReactionsCount returns value of UnreadReactionsCount field.
func ( *MonoForumDialog) () ( int) {
	if  == nil {
		return
	}
	return .UnreadReactionsCount
}

// SetDraft sets value of Draft conditional field.
func ( *MonoForumDialog) ( DraftMessageClass) {
	.Flags.Set(1)
	.Draft = 
}

// GetDraft returns value of Draft conditional field and
// boolean which is true if field was set.
func ( *MonoForumDialog) () ( DraftMessageClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Draft, true
}

// SavedDialogClassName is schema name of SavedDialogClass.
const SavedDialogClassName = "SavedDialog"

// SavedDialogClass represents SavedDialog generic type.
//
// See https://core.telegram.org/type/SavedDialog for reference.
//
// Constructors:
//   - [SavedDialog]
//   - [MonoForumDialog]
//
// Example:
//
//	g, err := tg.DecodeSavedDialog(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.SavedDialog: // savedDialog#bd87cb6c
//	case *tg.MonoForumDialog: // monoForumDialog#64407ea7
//	default: panic(v)
//	}
type SavedDialogClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() SavedDialogClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// The dialog
	GetPeer() (value PeerClass)

	// The latest message ID
	GetTopMessage() (value int)
}

// DecodeSavedDialog implements binary de-serialization for SavedDialogClass.
func ( *bin.Buffer) (SavedDialogClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case SavedDialogTypeID:
		// Decoding savedDialog#bd87cb6c.
		 := SavedDialog{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode SavedDialogClass: %w", )
		}
		return &, nil
	case MonoForumDialogTypeID:
		// Decoding monoForumDialog#64407ea7.
		 := MonoForumDialog{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode SavedDialogClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode SavedDialogClass: %w", bin.NewUnexpectedID())
	}
}

// SavedDialog boxes the SavedDialogClass providing a helper.
type SavedDialogBox struct {
	SavedDialog SavedDialogClass
}

// Decode implements bin.Decoder for SavedDialogBox.
func ( *SavedDialogBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode SavedDialogBox to nil")
	}
	,  := DecodeSavedDialog()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.SavedDialog = 
	return nil
}

// Encode implements bin.Encode for SavedDialogBox.
func ( *SavedDialogBox) ( *bin.Buffer) error {
	if  == nil || .SavedDialog == nil {
		return fmt.Errorf("unable to encode SavedDialogClass as nil")
	}
	return .SavedDialog.Encode()
}