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

// StatsGraphAsync represents TL type `statsGraphAsync#4a27eb2d`.
// This channel statistics graph¹ must be generated asynchronously using stats
// loadAsyncGraph² to reduce server load
//
// Links:
//  1. https://core.telegram.org/api/stats
//  2. https://core.telegram.org/method/stats.loadAsyncGraph
//
// See https://core.telegram.org/constructor/statsGraphAsync for reference.
type StatsGraphAsync struct {
	// Token to use for fetching the async graph
	Token string
}

// StatsGraphAsyncTypeID is TL type id of StatsGraphAsync.
const StatsGraphAsyncTypeID = 0x4a27eb2d

// construct implements constructor of StatsGraphClass.
func ( StatsGraphAsync) () StatsGraphClass { return & }

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

	_ StatsGraphClass = &StatsGraphAsync{}
)

func ( *StatsGraphAsync) () bool {
	if  == nil {
		return true
	}
	if !(.Token == "") {
		return false
	}

	return true
}

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

// FillFrom fills StatsGraphAsync from given interface.
func ( *StatsGraphAsync) ( interface {
	() ( string)
}) {
	.Token = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StatsGraphAsync) () tdp.Type {
	 := tdp.Type{
		Name: "statsGraphAsync",
		ID:   StatsGraphAsyncTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Token",
			SchemaName: "token",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *StatsGraphAsync) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode statsGraphAsync#4a27eb2d as nil")
	}
	.PutID(StatsGraphAsyncTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StatsGraphAsync) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode statsGraphAsync#4a27eb2d as nil")
	}
	.PutString(.Token)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StatsGraphAsync) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode statsGraphAsync#4a27eb2d to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode statsGraphAsync#4a27eb2d: field token: %w", )
		}
		.Token = 
	}
	return nil
}

// GetToken returns value of Token field.
func ( *StatsGraphAsync) () ( string) {
	if  == nil {
		return
	}
	return .Token
}

// StatsGraphError represents TL type `statsGraphError#bedc9822`.
// An error occurred while generating the statistics graph¹
//
// Links:
//  1. https://core.telegram.org/api/stats
//
// See https://core.telegram.org/constructor/statsGraphError for reference.
type StatsGraphError struct {
	// The error
	Error string
}

// StatsGraphErrorTypeID is TL type id of StatsGraphError.
const StatsGraphErrorTypeID = 0xbedc9822

// construct implements constructor of StatsGraphClass.
func ( StatsGraphError) () StatsGraphClass { return & }

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

	_ StatsGraphClass = &StatsGraphError{}
)

func ( *StatsGraphError) () bool {
	if  == nil {
		return true
	}
	if !(.Error == "") {
		return false
	}

	return true
}

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

// FillFrom fills StatsGraphError from given interface.
func ( *StatsGraphError) ( interface {
	() ( string)
}) {
	.Error = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StatsGraphError) () tdp.Type {
	 := tdp.Type{
		Name: "statsGraphError",
		ID:   StatsGraphErrorTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Error",
			SchemaName: "error",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *StatsGraphError) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode statsGraphError#bedc9822 as nil")
	}
	.PutID(StatsGraphErrorTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StatsGraphError) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode statsGraphError#bedc9822 as nil")
	}
	.PutString(.Error)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StatsGraphError) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode statsGraphError#bedc9822 to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode statsGraphError#bedc9822: field error: %w", )
		}
		.Error = 
	}
	return nil
}

// GetError returns value of Error field.
func ( *StatsGraphError) () ( string) {
	if  == nil {
		return
	}
	return .Error
}

// StatsGraph represents TL type `statsGraph#8ea464b6`.
// Channel statistics graph¹
//
// Links:
//  1. https://core.telegram.org/api/stats
//
// See https://core.telegram.org/constructor/statsGraph for reference.
type StatsGraph struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Statistics data
	JSON DataJSON
	// Zoom token
	//
	// Use SetZoomToken and GetZoomToken helpers.
	ZoomToken string
}

// StatsGraphTypeID is TL type id of StatsGraph.
const StatsGraphTypeID = 0x8ea464b6

// construct implements constructor of StatsGraphClass.
func ( StatsGraph) () StatsGraphClass { return & }

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

	_ StatsGraphClass = &StatsGraph{}
)

func ( *StatsGraph) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.JSON.Zero()) {
		return false
	}
	if !(.ZoomToken == "") {
		return false
	}

	return true
}

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

// FillFrom fills StatsGraph from given interface.
func ( *StatsGraph) ( interface {
	() ( DataJSON)
	() ( string,  bool)
}) {
	.JSON = .()
	if ,  := .();  {
		.ZoomToken = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *StatsGraph) () tdp.Type {
	 := tdp.Type{
		Name: "statsGraph",
		ID:   StatsGraphTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "JSON",
			SchemaName: "json",
		},
		{
			Name:       "ZoomToken",
			SchemaName: "zoom_token",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StatsGraph) () {
	if !(.ZoomToken == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *StatsGraph) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode statsGraph#8ea464b6 as nil")
	}
	.PutID(StatsGraphTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StatsGraph) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode statsGraph#8ea464b6 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode statsGraph#8ea464b6: field flags: %w", )
	}
	if  := .JSON.Encode();  != nil {
		return fmt.Errorf("unable to encode statsGraph#8ea464b6: field json: %w", )
	}
	if .Flags.Has(0) {
		.PutString(.ZoomToken)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StatsGraph) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode statsGraph#8ea464b6 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode statsGraph#8ea464b6: field flags: %w", )
		}
	}
	{
		if  := .JSON.Decode();  != nil {
			return fmt.Errorf("unable to decode statsGraph#8ea464b6: field json: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode statsGraph#8ea464b6: field zoom_token: %w", )
		}
		.ZoomToken = 
	}
	return nil
}

// GetJSON returns value of JSON field.
func ( *StatsGraph) () ( DataJSON) {
	if  == nil {
		return
	}
	return .JSON
}

// SetZoomToken sets value of ZoomToken conditional field.
func ( *StatsGraph) ( string) {
	.Flags.Set(0)
	.ZoomToken = 
}

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

// StatsGraphClassName is schema name of StatsGraphClass.
const StatsGraphClassName = "StatsGraph"

// StatsGraphClass represents StatsGraph generic type.
//
// See https://core.telegram.org/type/StatsGraph for reference.
//
// Example:
//
//	g, err := tg.DecodeStatsGraph(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.StatsGraphAsync: // statsGraphAsync#4a27eb2d
//	case *tg.StatsGraphError: // statsGraphError#bedc9822
//	case *tg.StatsGraph: // statsGraph#8ea464b6
//	default: panic(v)
//	}
type StatsGraphClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StatsGraphClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool
}

// DecodeStatsGraph implements binary de-serialization for StatsGraphClass.
func ( *bin.Buffer) (StatsGraphClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case StatsGraphAsyncTypeID:
		// Decoding statsGraphAsync#4a27eb2d.
		 := StatsGraphAsync{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", )
		}
		return &, nil
	case StatsGraphErrorTypeID:
		// Decoding statsGraphError#bedc9822.
		 := StatsGraphError{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", )
		}
		return &, nil
	case StatsGraphTypeID:
		// Decoding statsGraph#8ea464b6.
		 := StatsGraph{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", bin.NewUnexpectedID())
	}
}

// StatsGraph boxes the StatsGraphClass providing a helper.
type StatsGraphBox struct {
	StatsGraph StatsGraphClass
}

// Decode implements bin.Decoder for StatsGraphBox.
func ( *StatsGraphBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode StatsGraphBox to nil")
	}
	,  := DecodeStatsGraph()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.StatsGraph = 
	return nil
}

// Encode implements bin.Encode for StatsGraphBox.
func ( *StatsGraphBox) ( *bin.Buffer) error {
	if  == nil || .StatsGraph == nil {
		return fmt.Errorf("unable to encode StatsGraphClass as nil")
	}
	return .StatsGraph.Encode()
}