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

// AccountToggleNoPaidMessagesExceptionRequest represents TL type `account.toggleNoPaidMessagesException#fe2eda76`.
// Allow a user to send us messages without paying if paid messages »¹ are enabled.
//
// Links:
//  1. https://core.telegram.org/api/paid-messages
//
// See https://core.telegram.org/method/account.toggleNoPaidMessagesException for reference.
type AccountToggleNoPaidMessagesExceptionRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set and require_payment is not set, refunds the amounts the user has already paid
	// us to send us messages (directly or via a monoforum).
	RefundCharged bool
	// If set, requires the user to pay in order to send us messages. Can only be set by
	// monoforums, not users, i.e. parent_peer must be set if this flag is set; users must
	// instead use the inputPrivacyKeyNoPaidMessages¹ privacy setting to remove a previously
	// added exemption. If not set, allows the user to send us messages without paying (can
	// be unset by both monoforums and users).
	//
	// Links:
	//  1) https://core.telegram.org/constructor/inputPrivacyKeyNoPaidMessages
	RequirePayment bool
	// If set, applies the setting within the monoforum aka direct messages »¹ (pass the ID
	// of the monoforum, not the ID of the associated channel).
	//
	// Links:
	//  1) https://core.telegram.org/api/monoforum
	//
	// Use SetParentPeer and GetParentPeer helpers.
	ParentPeer InputPeerClass
	// The user to exempt or unexempt.
	UserID InputUserClass
}

// AccountToggleNoPaidMessagesExceptionRequestTypeID is TL type id of AccountToggleNoPaidMessagesExceptionRequest.
const AccountToggleNoPaidMessagesExceptionRequestTypeID = 0xfe2eda76

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

func ( *AccountToggleNoPaidMessagesExceptionRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.RefundCharged == false) {
		return false
	}
	if !(.RequirePayment == false) {
		return false
	}
	if !(.ParentPeer == nil) {
		return false
	}
	if !(.UserID == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AccountToggleNoPaidMessagesExceptionRequest from given interface.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputPeerClass,  bool)
	() ( InputUserClass)
}) {
	.RefundCharged = .()
	.RequirePayment = .()
	if ,  := .();  {
		.ParentPeer = 
	}

	.UserID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *AccountToggleNoPaidMessagesExceptionRequest) () tdp.Type {
	 := tdp.Type{
		Name: "account.toggleNoPaidMessagesException",
		ID:   AccountToggleNoPaidMessagesExceptionRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "RefundCharged",
			SchemaName: "refund_charged",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "RequirePayment",
			SchemaName: "require_payment",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "ParentPeer",
			SchemaName: "parent_peer",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *AccountToggleNoPaidMessagesExceptionRequest) () {
	if !(.RefundCharged == false) {
		.Flags.Set(0)
	}
	if !(.RequirePayment == false) {
		.Flags.Set(2)
	}
	if !(.ParentPeer == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.toggleNoPaidMessagesException#fe2eda76 as nil")
	}
	.PutID(AccountToggleNoPaidMessagesExceptionRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode account.toggleNoPaidMessagesException#fe2eda76 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode account.toggleNoPaidMessagesException#fe2eda76: field flags: %w", )
	}
	if .Flags.Has(1) {
		if .ParentPeer == nil {
			return fmt.Errorf("unable to encode account.toggleNoPaidMessagesException#fe2eda76: field parent_peer is nil")
		}
		if  := .ParentPeer.Encode();  != nil {
			return fmt.Errorf("unable to encode account.toggleNoPaidMessagesException#fe2eda76: field parent_peer: %w", )
		}
	}
	if .UserID == nil {
		return fmt.Errorf("unable to encode account.toggleNoPaidMessagesException#fe2eda76: field user_id is nil")
	}
	if  := .UserID.Encode();  != nil {
		return fmt.Errorf("unable to encode account.toggleNoPaidMessagesException#fe2eda76: field user_id: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode account.toggleNoPaidMessagesException#fe2eda76 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode account.toggleNoPaidMessagesException#fe2eda76: field flags: %w", )
		}
	}
	.RefundCharged = .Flags.Has(0)
	.RequirePayment = .Flags.Has(2)
	if .Flags.Has(1) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode account.toggleNoPaidMessagesException#fe2eda76: field parent_peer: %w", )
		}
		.ParentPeer = 
	}
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode account.toggleNoPaidMessagesException#fe2eda76: field user_id: %w", )
		}
		.UserID = 
	}
	return nil
}

// SetRefundCharged sets value of RefundCharged conditional field.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.RefundCharged = true
	} else {
		.Flags.Unset(0)
		.RefundCharged = false
	}
}

// GetRefundCharged returns value of RefundCharged conditional field.
func ( *AccountToggleNoPaidMessagesExceptionRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetRequirePayment sets value of RequirePayment conditional field.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.RequirePayment = true
	} else {
		.Flags.Unset(2)
		.RequirePayment = false
	}
}

// GetRequirePayment returns value of RequirePayment conditional field.
func ( *AccountToggleNoPaidMessagesExceptionRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetParentPeer sets value of ParentPeer conditional field.
func ( *AccountToggleNoPaidMessagesExceptionRequest) ( InputPeerClass) {
	.Flags.Set(1)
	.ParentPeer = 
}

// GetParentPeer returns value of ParentPeer conditional field and
// boolean which is true if field was set.
func ( *AccountToggleNoPaidMessagesExceptionRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .ParentPeer, true
}

// GetUserID returns value of UserID field.
func ( *AccountToggleNoPaidMessagesExceptionRequest) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .UserID
}

// AccountToggleNoPaidMessagesException invokes method account.toggleNoPaidMessagesException#fe2eda76 returning error if any.
// Allow a user to send us messages without paying if paid messages »¹ are enabled.
//
// Links:
//  1. https://core.telegram.org/api/paid-messages
//
// Possible errors:
//
//	400 PARENT_PEER_INVALID: The specified parent_peer is invalid.
//	400 UNSUPPORTED: require_payment cannot be set by users, only by monoforums: users must instead use the inputPrivacyKeyNoPaidMessages privacy setting to remove a previously added exemption.
//	400 USER_ID_INVALID: The provided user ID is invalid.
//
// See https://core.telegram.org/method/account.toggleNoPaidMessagesException for reference.
func ( *Client) ( context.Context,  *AccountToggleNoPaidMessagesExceptionRequest) (bool, error) {
	var  BoolBox

	if  := .rpc.Invoke(, , &);  != nil {
		return false, 
	}
	,  := .Bool.(*BoolTrue)
	return , nil
}