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

// CommunityPeer represents TL type `communityPeer#76141ebd`.
//
// See https://core.telegram.org/constructor/communityPeer for reference.
type CommunityPeer struct {
	// Flags field of CommunityPeer.
	Flags bin.Fields
	// CanViewHistory field of CommunityPeer.
	CanViewHistory bool
	// Visible field of CommunityPeer.
	//
	// Use SetVisible and GetVisible helpers.
	Visible bool
	// Peer field of CommunityPeer.
	Peer PeerClass
}

// CommunityPeerTypeID is TL type id of CommunityPeer.
const CommunityPeerTypeID = 0x76141ebd

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

func ( *CommunityPeer) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.CanViewHistory == false) {
		return false
	}
	if !(.Visible == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}

	return true
}

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

// FillFrom fills CommunityPeer from given interface.
func ( *CommunityPeer) ( interface {
	() ( bool)
	() ( bool,  bool)
	() ( PeerClass)
}) {
	.CanViewHistory = .()
	if ,  := .();  {
		.Visible = 
	}

	.Peer = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *CommunityPeer) () tdp.Type {
	 := tdp.Type{
		Name: "communityPeer",
		ID:   CommunityPeerTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "CanViewHistory",
			SchemaName: "can_view_history",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Visible",
			SchemaName: "visible",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *CommunityPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode communityPeer#76141ebd as nil")
	}
	.PutID(CommunityPeerTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *CommunityPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode communityPeer#76141ebd as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode communityPeer#76141ebd: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutBool(.Visible)
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode communityPeer#76141ebd: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode communityPeer#76141ebd: field peer: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *CommunityPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode communityPeer#76141ebd to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode communityPeer#76141ebd: field flags: %w", )
		}
	}
	.CanViewHistory = .Flags.Has(2)
	if .Flags.Has(0) {
		,  := .Bool()
		if  != nil {
			return fmt.Errorf("unable to decode communityPeer#76141ebd: field visible: %w", )
		}
		.Visible = 
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode communityPeer#76141ebd: field peer: %w", )
		}
		.Peer = 
	}
	return nil
}

// SetCanViewHistory sets value of CanViewHistory conditional field.
func ( *CommunityPeer) ( bool) {
	if  {
		.Flags.Set(2)
		.CanViewHistory = true
	} else {
		.Flags.Unset(2)
		.CanViewHistory = false
	}
}

// GetCanViewHistory returns value of CanViewHistory conditional field.
func ( *CommunityPeer) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetVisible sets value of Visible conditional field.
func ( *CommunityPeer) ( bool) {
	.Flags.Set(0)
	.Visible = 
}

// GetVisible returns value of Visible conditional field and
// boolean which is true if field was set.
func ( *CommunityPeer) () ( bool,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Visible, true
}

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