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

// CurrentWeather represents TL type `currentWeather#eacea8c0`.
type CurrentWeather struct {
	// Temperature, in degree Celsius
	Temperature float64
	// Emoji representing the weather
	Emoji string
}

// CurrentWeatherTypeID is TL type id of CurrentWeather.
const CurrentWeatherTypeID = 0xeacea8c0

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

func (c *CurrentWeather) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Temperature == 0) {
		return false
	}
	if !(c.Emoji == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CurrentWeather) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "currentWeather",
		ID:   CurrentWeatherTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Temperature",
			SchemaName: "temperature",
		},
		{
			Name:       "Emoji",
			SchemaName: "emoji",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CurrentWeather) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode currentWeather#eacea8c0 as nil")
	}
	b.PutID(CurrentWeatherTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CurrentWeather) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode currentWeather#eacea8c0 as nil")
	}
	b.PutDouble(c.Temperature)
	b.PutString(c.Emoji)
	return nil
}

// Decode implements bin.Decoder.
func (c *CurrentWeather) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode currentWeather#eacea8c0 to nil")
	}
	if err := b.ConsumeID(CurrentWeatherTypeID); err != nil {
		return fmt.Errorf("unable to decode currentWeather#eacea8c0: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CurrentWeather) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode currentWeather#eacea8c0 to nil")
	}
	{
		value, err := b.Double()
		if err != nil {
			return fmt.Errorf("unable to decode currentWeather#eacea8c0: field temperature: %w", err)
		}
		c.Temperature = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode currentWeather#eacea8c0: field emoji: %w", err)
		}
		c.Emoji = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CurrentWeather) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode currentWeather#eacea8c0 as nil")
	}
	b.ObjStart()
	b.PutID("currentWeather")
	b.Comma()
	b.FieldStart("temperature")
	b.PutDouble(c.Temperature)
	b.Comma()
	b.FieldStart("emoji")
	b.PutString(c.Emoji)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CurrentWeather) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode currentWeather#eacea8c0 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("currentWeather"); err != nil {
				return fmt.Errorf("unable to decode currentWeather#eacea8c0: %w", err)
			}
		case "temperature":
			value, err := b.Double()
			if err != nil {
				return fmt.Errorf("unable to decode currentWeather#eacea8c0: field temperature: %w", err)
			}
			c.Temperature = value
		case "emoji":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode currentWeather#eacea8c0: field emoji: %w", err)
			}
			c.Emoji = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTemperature returns value of Temperature field.
func (c *CurrentWeather) GetTemperature() (value float64) {
	if c == nil {
		return
	}
	return c.Temperature
}

// GetEmoji returns value of Emoji field.
func (c *CurrentWeather) GetEmoji() (value string) {
	if c == nil {
		return
	}
	return c.Emoji
}
