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

// PeerSettings represents TL type `peerSettings#a518110d`.
// List of actions that are possible when interacting with this user, to be shown as
// suggested actions in the chat action bar »¹, see here »² for more info.
//
// Links:
//  1. https://core.telegram.org/api/action-bar
//  2. https://core.telegram.org/api/action-bar
//
// See https://core.telegram.org/constructor/peerSettings for reference.
type PeerSettings struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether we can still report the user for spam
	ReportSpam bool
	// Whether we can add the user as contact
	AddContact bool
	// Whether we can block the user
	BlockContact bool
	// Whether we can share the user's contact
	ShareContact bool
	// Whether a special exception for contacts is needed
	NeedContactsException bool
	// Whether we can report a geogroup as irrelevant for this location
	ReportGeo bool
	// Whether this peer was automatically archived according to privacy settings¹ and can
	// be unarchived
	//
	// Links:
	//  1) https://core.telegram.org/constructor/globalPrivacySettings
	Autoarchived bool
	// If set, this is a recently created group chat to which new members can be invited
	InviteMembers bool
	// This flag is set if request_chat_title and request_chat_date fields are set and the
	// join request »¹ is related to a channel (otherwise if only the request fields are
	// set, the join request »² is related to a chat).
	//
	// Links:
	//  1) https://core.telegram.org/api/invites#join-requests
	//  2) https://core.telegram.org/api/invites#join-requests
	RequestChatBroadcast bool
	// Distance in meters between us and this peer
	//
	// Use SetGeoDistance and GetGeoDistance helpers.
	GeoDistance int
	// If set, this is a private chat with an administrator of a chat or channel to which the
	// user sent a join request, and this field contains the chat/channel's title.
	//
	// Use SetRequestChatTitle and GetRequestChatTitle helpers.
	RequestChatTitle string
	// If set, this is a private chat with an administrator of a chat or channel to which the
	// user sent a join request, and this field contains the timestamp when the join request
	// »¹ was sent.
	//
	// Links:
	//  1) https://core.telegram.org/api/invites#join-requests
	//
	// Use SetRequestChatDate and GetRequestChatDate helpers.
	RequestChatDate int
}

// PeerSettingsTypeID is TL type id of PeerSettings.
const PeerSettingsTypeID = 0xa518110d

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

func ( *PeerSettings) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.ReportSpam == false) {
		return false
	}
	if !(.AddContact == false) {
		return false
	}
	if !(.BlockContact == false) {
		return false
	}
	if !(.ShareContact == false) {
		return false
	}
	if !(.NeedContactsException == false) {
		return false
	}
	if !(.ReportGeo == false) {
		return false
	}
	if !(.Autoarchived == false) {
		return false
	}
	if !(.InviteMembers == false) {
		return false
	}
	if !(.RequestChatBroadcast == false) {
		return false
	}
	if !(.GeoDistance == 0) {
		return false
	}
	if !(.RequestChatTitle == "") {
		return false
	}
	if !(.RequestChatDate == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PeerSettings from given interface.
func ( *PeerSettings) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int,  bool)
	() ( string,  bool)
	() ( int,  bool)
}) {
	.ReportSpam = .()
	.AddContact = .()
	.BlockContact = .()
	.ShareContact = .()
	.NeedContactsException = .()
	.ReportGeo = .()
	.Autoarchived = .()
	.InviteMembers = .()
	.RequestChatBroadcast = .()
	if ,  := .();  {
		.GeoDistance = 
	}

	if ,  := .();  {
		.RequestChatTitle = 
	}

	if ,  := .();  {
		.RequestChatDate = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *PeerSettings) () tdp.Type {
	 := tdp.Type{
		Name: "peerSettings",
		ID:   PeerSettingsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ReportSpam",
			SchemaName: "report_spam",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "AddContact",
			SchemaName: "add_contact",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "BlockContact",
			SchemaName: "block_contact",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "ShareContact",
			SchemaName: "share_contact",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "NeedContactsException",
			SchemaName: "need_contacts_exception",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ReportGeo",
			SchemaName: "report_geo",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Autoarchived",
			SchemaName: "autoarchived",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "InviteMembers",
			SchemaName: "invite_members",
			Null:       !.Flags.Has(8),
		},
		{
			Name:       "RequestChatBroadcast",
			SchemaName: "request_chat_broadcast",
			Null:       !.Flags.Has(10),
		},
		{
			Name:       "GeoDistance",
			SchemaName: "geo_distance",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "RequestChatTitle",
			SchemaName: "request_chat_title",
			Null:       !.Flags.Has(9),
		},
		{
			Name:       "RequestChatDate",
			SchemaName: "request_chat_date",
			Null:       !.Flags.Has(9),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PeerSettings) () {
	if !(.ReportSpam == false) {
		.Flags.Set(0)
	}
	if !(.AddContact == false) {
		.Flags.Set(1)
	}
	if !(.BlockContact == false) {
		.Flags.Set(2)
	}
	if !(.ShareContact == false) {
		.Flags.Set(3)
	}
	if !(.NeedContactsException == false) {
		.Flags.Set(4)
	}
	if !(.ReportGeo == false) {
		.Flags.Set(5)
	}
	if !(.Autoarchived == false) {
		.Flags.Set(7)
	}
	if !(.InviteMembers == false) {
		.Flags.Set(8)
	}
	if !(.RequestChatBroadcast == false) {
		.Flags.Set(10)
	}
	if !(.GeoDistance == 0) {
		.Flags.Set(6)
	}
	if !(.RequestChatTitle == "") {
		.Flags.Set(9)
	}
	if !(.RequestChatDate == 0) {
		.Flags.Set(9)
	}
}

// Encode implements bin.Encoder.
func ( *PeerSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerSettings#a518110d as nil")
	}
	.PutID(PeerSettingsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerSettings#a518110d as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode peerSettings#a518110d: field flags: %w", )
	}
	if .Flags.Has(6) {
		.PutInt(.GeoDistance)
	}
	if .Flags.Has(9) {
		.PutString(.RequestChatTitle)
	}
	if .Flags.Has(9) {
		.PutInt(.RequestChatDate)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerSettings) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerSettings#a518110d to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode peerSettings#a518110d: field flags: %w", )
		}
	}
	.ReportSpam = .Flags.Has(0)
	.AddContact = .Flags.Has(1)
	.BlockContact = .Flags.Has(2)
	.ShareContact = .Flags.Has(3)
	.NeedContactsException = .Flags.Has(4)
	.ReportGeo = .Flags.Has(5)
	.Autoarchived = .Flags.Has(7)
	.InviteMembers = .Flags.Has(8)
	.RequestChatBroadcast = .Flags.Has(10)
	if .Flags.Has(6) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerSettings#a518110d: field geo_distance: %w", )
		}
		.GeoDistance = 
	}
	if .Flags.Has(9) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode peerSettings#a518110d: field request_chat_title: %w", )
		}
		.RequestChatTitle = 
	}
	if .Flags.Has(9) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerSettings#a518110d: field request_chat_date: %w", )
		}
		.RequestChatDate = 
	}
	return nil
}

// SetReportSpam sets value of ReportSpam conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(0)
		.ReportSpam = true
	} else {
		.Flags.Unset(0)
		.ReportSpam = false
	}
}

// GetReportSpam returns value of ReportSpam conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetAddContact sets value of AddContact conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(1)
		.AddContact = true
	} else {
		.Flags.Unset(1)
		.AddContact = false
	}
}

// GetAddContact returns value of AddContact conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetBlockContact sets value of BlockContact conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(2)
		.BlockContact = true
	} else {
		.Flags.Unset(2)
		.BlockContact = false
	}
}

// GetBlockContact returns value of BlockContact conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetShareContact sets value of ShareContact conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(3)
		.ShareContact = true
	} else {
		.Flags.Unset(3)
		.ShareContact = false
	}
}

// GetShareContact returns value of ShareContact conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetNeedContactsException sets value of NeedContactsException conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(4)
		.NeedContactsException = true
	} else {
		.Flags.Unset(4)
		.NeedContactsException = false
	}
}

// GetNeedContactsException returns value of NeedContactsException conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetReportGeo sets value of ReportGeo conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(5)
		.ReportGeo = true
	} else {
		.Flags.Unset(5)
		.ReportGeo = false
	}
}

// GetReportGeo returns value of ReportGeo conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetAutoarchived sets value of Autoarchived conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(7)
		.Autoarchived = true
	} else {
		.Flags.Unset(7)
		.Autoarchived = false
	}
}

// GetAutoarchived returns value of Autoarchived conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

// SetInviteMembers sets value of InviteMembers conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(8)
		.InviteMembers = true
	} else {
		.Flags.Unset(8)
		.InviteMembers = false
	}
}

// GetInviteMembers returns value of InviteMembers conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(8)
}

// SetRequestChatBroadcast sets value of RequestChatBroadcast conditional field.
func ( *PeerSettings) ( bool) {
	if  {
		.Flags.Set(10)
		.RequestChatBroadcast = true
	} else {
		.Flags.Unset(10)
		.RequestChatBroadcast = false
	}
}

// GetRequestChatBroadcast returns value of RequestChatBroadcast conditional field.
func ( *PeerSettings) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(10)
}

// SetGeoDistance sets value of GeoDistance conditional field.
func ( *PeerSettings) ( int) {
	.Flags.Set(6)
	.GeoDistance = 
}

// GetGeoDistance returns value of GeoDistance conditional field and
// boolean which is true if field was set.
func ( *PeerSettings) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .GeoDistance, true
}

// SetRequestChatTitle sets value of RequestChatTitle conditional field.
func ( *PeerSettings) ( string) {
	.Flags.Set(9)
	.RequestChatTitle = 
}

// GetRequestChatTitle returns value of RequestChatTitle conditional field and
// boolean which is true if field was set.
func ( *PeerSettings) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(9) {
		return , false
	}
	return .RequestChatTitle, true
}

// SetRequestChatDate sets value of RequestChatDate conditional field.
func ( *PeerSettings) ( int) {
	.Flags.Set(9)
	.RequestChatDate = 
}

// GetRequestChatDate returns value of RequestChatDate conditional field and
// boolean which is true if field was set.
func ( *PeerSettings) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(9) {
		return , false
	}
	return .RequestChatDate, true
}