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

// AutoDownloadSettingsPresets represents TL type `autoDownloadSettingsPresets#d1621d22`.
type AutoDownloadSettingsPresets struct {
	// Preset with lowest settings; expected to be used by default when roaming
	Low AutoDownloadSettings
	// Preset with medium settings; expected to be used by default when using mobile data
	Medium AutoDownloadSettings
	// Preset with highest settings; expected to be used by default when connected on Wi-Fi
	High AutoDownloadSettings
}

// AutoDownloadSettingsPresetsTypeID is TL type id of AutoDownloadSettingsPresets.
const AutoDownloadSettingsPresetsTypeID = 0xd1621d22

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

func (a *AutoDownloadSettingsPresets) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Low.Zero()) {
		return false
	}
	if !(a.Medium.Zero()) {
		return false
	}
	if !(a.High.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AutoDownloadSettingsPresets) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "autoDownloadSettingsPresets",
		ID:   AutoDownloadSettingsPresetsTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Low",
			SchemaName: "low",
		},
		{
			Name:       "Medium",
			SchemaName: "medium",
		},
		{
			Name:       "High",
			SchemaName: "high",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AutoDownloadSettingsPresets) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode autoDownloadSettingsPresets#d1621d22 as nil")
	}
	b.PutID(AutoDownloadSettingsPresetsTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AutoDownloadSettingsPresets) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode autoDownloadSettingsPresets#d1621d22 as nil")
	}
	if err := a.Low.Encode(b); err != nil {
		return fmt.Errorf("unable to encode autoDownloadSettingsPresets#d1621d22: field low: %w", err)
	}
	if err := a.Medium.Encode(b); err != nil {
		return fmt.Errorf("unable to encode autoDownloadSettingsPresets#d1621d22: field medium: %w", err)
	}
	if err := a.High.Encode(b); err != nil {
		return fmt.Errorf("unable to encode autoDownloadSettingsPresets#d1621d22: field high: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (a *AutoDownloadSettingsPresets) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode autoDownloadSettingsPresets#d1621d22 to nil")
	}
	if err := b.ConsumeID(AutoDownloadSettingsPresetsTypeID); err != nil {
		return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AutoDownloadSettingsPresets) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode autoDownloadSettingsPresets#d1621d22 to nil")
	}
	{
		if err := a.Low.Decode(b); err != nil {
			return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: field low: %w", err)
		}
	}
	{
		if err := a.Medium.Decode(b); err != nil {
			return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: field medium: %w", err)
		}
	}
	{
		if err := a.High.Decode(b); err != nil {
			return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: field high: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AutoDownloadSettingsPresets) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode autoDownloadSettingsPresets#d1621d22 as nil")
	}
	b.ObjStart()
	b.PutID("autoDownloadSettingsPresets")
	b.Comma()
	b.FieldStart("low")
	if err := a.Low.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode autoDownloadSettingsPresets#d1621d22: field low: %w", err)
	}
	b.Comma()
	b.FieldStart("medium")
	if err := a.Medium.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode autoDownloadSettingsPresets#d1621d22: field medium: %w", err)
	}
	b.Comma()
	b.FieldStart("high")
	if err := a.High.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode autoDownloadSettingsPresets#d1621d22: field high: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AutoDownloadSettingsPresets) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode autoDownloadSettingsPresets#d1621d22 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("autoDownloadSettingsPresets"); err != nil {
				return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: %w", err)
			}
		case "low":
			if err := a.Low.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: field low: %w", err)
			}
		case "medium":
			if err := a.Medium.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: field medium: %w", err)
			}
		case "high":
			if err := a.High.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode autoDownloadSettingsPresets#d1621d22: field high: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLow returns value of Low field.
func (a *AutoDownloadSettingsPresets) GetLow() (value AutoDownloadSettings) {
	if a == nil {
		return
	}
	return a.Low
}

// GetMedium returns value of Medium field.
func (a *AutoDownloadSettingsPresets) GetMedium() (value AutoDownloadSettings) {
	if a == nil {
		return
	}
	return a.Medium
}

// GetHigh returns value of High field.
func (a *AutoDownloadSettingsPresets) GetHigh() (value AutoDownloadSettings) {
	if a == nil {
		return
	}
	return a.High
}
