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

// StatsGetMegagroupStatsRequest represents TL type `stats.getMegagroupStats#dcdf8607`.
// Get supergroup statistics¹
//
// Links:
//  1. https://core.telegram.org/api/stats
//
// See https://core.telegram.org/method/stats.getMegagroupStats for reference.
type StatsGetMegagroupStatsRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether to enable dark theme for graph colors
	Dark bool
	// Supergroup ID¹
	//
	// Links:
	//  1) https://core.telegram.org/api/channel
	Channel InputChannelClass
}

// StatsGetMegagroupStatsRequestTypeID is TL type id of StatsGetMegagroupStatsRequest.
const StatsGetMegagroupStatsRequestTypeID = 0xdcdf8607

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

func ( *StatsGetMegagroupStatsRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Dark == false) {
		return false
	}
	if !(.Channel == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StatsGetMegagroupStatsRequest from given interface.
func ( *StatsGetMegagroupStatsRequest) ( interface {
	() ( bool)
	() ( InputChannelClass)
}) {
	.Dark = .()
	.Channel = .()
}

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

// TypeName returns name of type in TL schema.
func (*StatsGetMegagroupStatsRequest) () string {
	return "stats.getMegagroupStats"
}

// TypeInfo returns info about TL type.
func ( *StatsGetMegagroupStatsRequest) () tdp.Type {
	 := tdp.Type{
		Name: "stats.getMegagroupStats",
		ID:   StatsGetMegagroupStatsRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Dark",
			SchemaName: "dark",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Channel",
			SchemaName: "channel",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *StatsGetMegagroupStatsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stats.getMegagroupStats#dcdf8607 as nil")
	}
	.PutID(StatsGetMegagroupStatsRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StatsGetMegagroupStatsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stats.getMegagroupStats#dcdf8607 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stats.getMegagroupStats#dcdf8607: field flags: %w", )
	}
	if .Channel == nil {
		return fmt.Errorf("unable to encode stats.getMegagroupStats#dcdf8607: field channel is nil")
	}
	if  := .Channel.Encode();  != nil {
		return fmt.Errorf("unable to encode stats.getMegagroupStats#dcdf8607: field channel: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StatsGetMegagroupStatsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stats.getMegagroupStats#dcdf8607 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stats.getMegagroupStats#dcdf8607: field flags: %w", )
		}
	}
	.Dark = .Flags.Has(0)
	{
		,  := DecodeInputChannel()
		if  != nil {
			return fmt.Errorf("unable to decode stats.getMegagroupStats#dcdf8607: field channel: %w", )
		}
		.Channel = 
	}
	return nil
}

// SetDark sets value of Dark conditional field.
func ( *StatsGetMegagroupStatsRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Dark = true
	} else {
		.Flags.Unset(0)
		.Dark = false
	}
}

// GetDark returns value of Dark conditional field.
func ( *StatsGetMegagroupStatsRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetChannel returns value of Channel field.
func ( *StatsGetMegagroupStatsRequest) () ( InputChannelClass) {
	if  == nil {
		return
	}
	return .Channel
}

// GetChannelAsNotEmpty returns mapped value of Channel field.
func ( *StatsGetMegagroupStatsRequest) () (NotEmptyInputChannel, bool) {
	return .Channel.AsNotEmpty()
}

// StatsGetMegagroupStats invokes method stats.getMegagroupStats#dcdf8607 returning error if any.
// Get supergroup statistics¹
//
// Links:
//  1. https://core.telegram.org/api/stats
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	403 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	400 MEGAGROUP_REQUIRED: You can only use this method on a supergroup.
//
// See https://core.telegram.org/method/stats.getMegagroupStats for reference.
func ( *Client) ( context.Context,  *StatsGetMegagroupStatsRequest) (*StatsMegagroupStats, error) {
	var  StatsMegagroupStats

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return &, nil
}