// Code generated by gotdgen, DO NOT EDIT.

package tdapi

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

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

// GetTimeZonesRequest represents TL type `getTimeZones#4fe2e058`.
type GetTimeZonesRequest struct {
}

// GetTimeZonesRequestTypeID is TL type id of GetTimeZonesRequest.
const GetTimeZonesRequestTypeID = 0x4fe2e058

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

func (g *GetTimeZonesRequest) Zero() bool {
	if g == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetTimeZonesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getTimeZones",
		ID:   GetTimeZonesRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetTimeZonesRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getTimeZones#4fe2e058 as nil")
	}
	b.PutID(GetTimeZonesRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetTimeZonesRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getTimeZones#4fe2e058 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (g *GetTimeZonesRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getTimeZones#4fe2e058 to nil")
	}
	if err := b.ConsumeID(GetTimeZonesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getTimeZones#4fe2e058: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetTimeZonesRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getTimeZones#4fe2e058 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetTimeZonesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getTimeZones#4fe2e058 as nil")
	}
	b.ObjStart()
	b.PutID("getTimeZones")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetTimeZonesRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getTimeZones#4fe2e058 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getTimeZones"); err != nil {
				return fmt.Errorf("unable to decode getTimeZones#4fe2e058: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTimeZones invokes method getTimeZones#4fe2e058 returning error if any.
func (c *Client) GetTimeZones(ctx context.Context) (*TimeZones, error) {
	var result TimeZones

	request := &GetTimeZonesRequest{}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return &result, nil
}
