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

// FactCheck represents TL type `factCheck#b89bfccf`.
// Represents a fact-check »¹ created by an independent fact-checker.
//
// Links:
//  1. https://core.telegram.org/api/factcheck
//
// See https://core.telegram.org/constructor/factCheck for reference.
type FactCheck struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the country/text fields will not be set, and the fact check must be fetched
	// manually by the client (if it isn't already cached with the key specified in hash)
	// using bundled messages.getFactCheck¹ requests, when the message with the factcheck
	// scrolls into view.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.getFactCheck
	NeedCheck bool
	// A two-letter ISO 3166-1 alpha-2 country code of the country for which the fact-check
	// should be shown.
	//
	// Use SetCountry and GetCountry helpers.
	Country string
	// The fact-check.
	//
	// Use SetText and GetText helpers.
	Text TextWithEntities
	// Hash used for caching, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int64
}

// FactCheckTypeID is TL type id of FactCheck.
const FactCheckTypeID = 0xb89bfccf

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

func ( *FactCheck) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.NeedCheck == false) {
		return false
	}
	if !(.Country == "") {
		return false
	}
	if !(.Text.Zero()) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills FactCheck from given interface.
func ( *FactCheck) ( interface {
	() ( bool)
	() ( string,  bool)
	() ( TextWithEntities,  bool)
	() ( int64)
}) {
	.NeedCheck = .()
	if ,  := .();  {
		.Country = 
	}

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

	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *FactCheck) () tdp.Type {
	 := tdp.Type{
		Name: "factCheck",
		ID:   FactCheckTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "NeedCheck",
			SchemaName: "need_check",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Country",
			SchemaName: "country",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Text",
			SchemaName: "text",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *FactCheck) () {
	if !(.NeedCheck == false) {
		.Flags.Set(0)
	}
	if !(.Country == "") {
		.Flags.Set(1)
	}
	if !(.Text.Zero()) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *FactCheck) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode factCheck#b89bfccf as nil")
	}
	.PutID(FactCheckTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *FactCheck) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode factCheck#b89bfccf as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode factCheck#b89bfccf: field flags: %w", )
	}
	if .Flags.Has(1) {
		.PutString(.Country)
	}
	if .Flags.Has(1) {
		if  := .Text.Encode();  != nil {
			return fmt.Errorf("unable to encode factCheck#b89bfccf: field text: %w", )
		}
	}
	.PutLong(.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *FactCheck) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode factCheck#b89bfccf to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode factCheck#b89bfccf: field flags: %w", )
		}
	}
	.NeedCheck = .Flags.Has(0)
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode factCheck#b89bfccf: field country: %w", )
		}
		.Country = 
	}
	if .Flags.Has(1) {
		if  := .Text.Decode();  != nil {
			return fmt.Errorf("unable to decode factCheck#b89bfccf: field text: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode factCheck#b89bfccf: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

// SetNeedCheck sets value of NeedCheck conditional field.
func ( *FactCheck) ( bool) {
	if  {
		.Flags.Set(0)
		.NeedCheck = true
	} else {
		.Flags.Unset(0)
		.NeedCheck = false
	}
}

// GetNeedCheck returns value of NeedCheck conditional field.
func ( *FactCheck) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetCountry sets value of Country conditional field.
func ( *FactCheck) ( string) {
	.Flags.Set(1)
	.Country = 
}

// GetCountry returns value of Country conditional field and
// boolean which is true if field was set.
func ( *FactCheck) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Country, true
}

// SetText sets value of Text conditional field.
func ( *FactCheck) ( TextWithEntities) {
	.Flags.Set(1)
	.Text = 
}

// GetText returns value of Text conditional field and
// boolean which is true if field was set.
func ( *FactCheck) () ( TextWithEntities,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Text, true
}

// GetHash returns value of Hash field.
func ( *FactCheck) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}