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

// CommunityPeerRequest represents TL type `communityPeerRequest#7beafa85`.
//
// See https://core.telegram.org/constructor/communityPeerRequest for reference.
type CommunityPeerRequest struct {
	// Flags field of CommunityPeerRequest.
	Flags bin.Fields
	// Visible field of CommunityPeerRequest.
	Visible bool
	// Peer field of CommunityPeerRequest.
	Peer PeerClass
	// RequestedBy field of CommunityPeerRequest.
	RequestedBy int64
	// Date field of CommunityPeerRequest.
	Date int
}

// CommunityPeerRequestTypeID is TL type id of CommunityPeerRequest.
const CommunityPeerRequestTypeID = 0x7beafa85

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

func ( *CommunityPeerRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Visible == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.RequestedBy == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}

	return true
}

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

// FillFrom fills CommunityPeerRequest from given interface.
func ( *CommunityPeerRequest) ( interface {
	() ( bool)
	() ( PeerClass)
	() ( int64)
	() ( int)
}) {
	.Visible = .()
	.Peer = .()
	.RequestedBy = .()
	.Date = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *CommunityPeerRequest) () tdp.Type {
	 := tdp.Type{
		Name: "communityPeerRequest",
		ID:   CommunityPeerRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Visible",
			SchemaName: "visible",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "RequestedBy",
			SchemaName: "requested_by",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *CommunityPeerRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode communityPeerRequest#7beafa85 as nil")
	}
	.PutID(CommunityPeerRequestTypeID)
	return .EncodeBare()
}

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

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

// DecodeBare implements bin.BareDecoder.
func ( *CommunityPeerRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode communityPeerRequest#7beafa85 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode communityPeerRequest#7beafa85: field flags: %w", )
		}
	}
	.Visible = .Flags.Has(0)
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode communityPeerRequest#7beafa85: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode communityPeerRequest#7beafa85: field requested_by: %w", )
		}
		.RequestedBy = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode communityPeerRequest#7beafa85: field date: %w", )
		}
		.Date = 
	}
	return nil
}

// SetVisible sets value of Visible conditional field.
func ( *CommunityPeerRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Visible = true
	} else {
		.Flags.Unset(0)
		.Visible = false
	}
}

// GetVisible returns value of Visible conditional field.
func ( *CommunityPeerRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

// GetRequestedBy returns value of RequestedBy field.
func ( *CommunityPeerRequest) () ( int64) {
	if  == nil {
		return
	}
	return .RequestedBy
}

// GetDate returns value of Date field.
func ( *CommunityPeerRequest) () ( int) {
	if  == nil {
		return
	}
	return .Date
}