// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// StarGiftActiveAuctionState represents TL type `starGiftActiveAuctionState#d31bc45d`.
//
// See https://core.telegram.org/constructor/starGiftActiveAuctionState for reference.
type StarGiftActiveAuctionState struct {
	// Gift field of StarGiftActiveAuctionState.
	Gift StarGiftClass
	// State field of StarGiftActiveAuctionState.
	State StarGiftAuctionStateClass
	// UserState field of StarGiftActiveAuctionState.
	UserState StarGiftAuctionUserState
}

// StarGiftActiveAuctionStateTypeID is TL type id of StarGiftActiveAuctionState.
const StarGiftActiveAuctionStateTypeID = 0xd31bc45d

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

func (s *StarGiftActiveAuctionState) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Gift == nil) {
		return false
	}
	if !(s.State == nil) {
		return false
	}
	if !(s.UserState.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftActiveAuctionState from given interface.
func (s *StarGiftActiveAuctionState) FillFrom(from interface {
	GetGift() (value StarGiftClass)
	GetState() (value StarGiftAuctionStateClass)
	GetUserState() (value StarGiftAuctionUserState)
}) {
	s.Gift = from.GetGift()
	s.State = from.GetState()
	s.UserState = from.GetUserState()
}

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

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

// TypeInfo returns info about TL type.
func (s *StarGiftActiveAuctionState) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiftActiveAuctionState",
		ID:   StarGiftActiveAuctionStateTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Gift",
			SchemaName: "gift",
		},
		{
			Name:       "State",
			SchemaName: "state",
		},
		{
			Name:       "UserState",
			SchemaName: "user_state",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiftActiveAuctionState) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftActiveAuctionState#d31bc45d as nil")
	}
	b.PutID(StarGiftActiveAuctionStateTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiftActiveAuctionState) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiftActiveAuctionState#d31bc45d as nil")
	}
	if s.Gift == nil {
		return fmt.Errorf("unable to encode starGiftActiveAuctionState#d31bc45d: field gift is nil")
	}
	if err := s.Gift.Encode(b); err != nil {
		return fmt.Errorf("unable to encode starGiftActiveAuctionState#d31bc45d: field gift: %w", err)
	}
	if s.State == nil {
		return fmt.Errorf("unable to encode starGiftActiveAuctionState#d31bc45d: field state is nil")
	}
	if err := s.State.Encode(b); err != nil {
		return fmt.Errorf("unable to encode starGiftActiveAuctionState#d31bc45d: field state: %w", err)
	}
	if err := s.UserState.Encode(b); err != nil {
		return fmt.Errorf("unable to encode starGiftActiveAuctionState#d31bc45d: field user_state: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *StarGiftActiveAuctionState) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftActiveAuctionState#d31bc45d to nil")
	}
	if err := b.ConsumeID(StarGiftActiveAuctionStateTypeID); err != nil {
		return fmt.Errorf("unable to decode starGiftActiveAuctionState#d31bc45d: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *StarGiftActiveAuctionState) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiftActiveAuctionState#d31bc45d to nil")
	}
	{
		value, err := DecodeStarGift(b)
		if err != nil {
			return fmt.Errorf("unable to decode starGiftActiveAuctionState#d31bc45d: field gift: %w", err)
		}
		s.Gift = value
	}
	{
		value, err := DecodeStarGiftAuctionState(b)
		if err != nil {
			return fmt.Errorf("unable to decode starGiftActiveAuctionState#d31bc45d: field state: %w", err)
		}
		s.State = value
	}
	{
		if err := s.UserState.Decode(b); err != nil {
			return fmt.Errorf("unable to decode starGiftActiveAuctionState#d31bc45d: field user_state: %w", err)
		}
	}
	return nil
}

// GetGift returns value of Gift field.
func (s *StarGiftActiveAuctionState) GetGift() (value StarGiftClass) {
	if s == nil {
		return
	}
	return s.Gift
}

// GetState returns value of State field.
func (s *StarGiftActiveAuctionState) GetState() (value StarGiftAuctionStateClass) {
	if s == nil {
		return
	}
	return s.State
}

// GetUserState returns value of UserState field.
func (s *StarGiftActiveAuctionState) GetUserState() (value StarGiftAuctionUserState) {
	if s == nil {
		return
	}
	return s.UserState
}

// GetStateAsModified returns mapped value of State field.
func (s *StarGiftActiveAuctionState) GetStateAsModified() (ModifiedStarGiftAuctionState, bool) {
	return s.State.AsModified()
}
