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

// SendAsPeer represents TL type `sendAsPeer#b81c7034`.
// Indicates a peer that can be used to send messages
//
// See https://core.telegram.org/constructor/sendAsPeer for reference.
type SendAsPeer struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether a Telegram Premium account is required to send messages as this peer
	PremiumRequired bool
	// Peer
	Peer PeerClass
}

// SendAsPeerTypeID is TL type id of SendAsPeer.
const SendAsPeerTypeID = 0xb81c7034

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

func ( *SendAsPeer) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.PremiumRequired == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}

	return true
}

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

// FillFrom fills SendAsPeer from given interface.
func ( *SendAsPeer) ( interface {
	() ( bool)
	() ( PeerClass)
}) {
	.PremiumRequired = .()
	.Peer = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *SendAsPeer) () tdp.Type {
	 := tdp.Type{
		Name: "sendAsPeer",
		ID:   SendAsPeerTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "PremiumRequired",
			SchemaName: "premium_required",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SendAsPeer) () {
	if !(.PremiumRequired == false) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *SendAsPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode sendAsPeer#b81c7034 as nil")
	}
	.PutID(SendAsPeerTypeID)
	return .EncodeBare()
}

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

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

// DecodeBare implements bin.BareDecoder.
func ( *SendAsPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode sendAsPeer#b81c7034 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode sendAsPeer#b81c7034: field flags: %w", )
		}
	}
	.PremiumRequired = .Flags.Has(0)
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode sendAsPeer#b81c7034: field peer: %w", )
		}
		.Peer = 
	}
	return nil
}

// SetPremiumRequired sets value of PremiumRequired conditional field.
func ( *SendAsPeer) ( bool) {
	if  {
		.Flags.Set(0)
		.PremiumRequired = true
	} else {
		.Flags.Unset(0)
		.PremiumRequired = false
	}
}

// GetPremiumRequired returns value of PremiumRequired conditional field.
func ( *SendAsPeer) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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