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

// StarGiveawayWinnerOption represents TL type `starGiveawayWinnerOption#cc639607`.
type StarGiveawayWinnerOption struct {
	// The number of users that will be chosen as winners
	WinnerCount int32
	// The number of Telegram Stars that will be won by the winners of the giveaway
	WonStarCount int64
	// True, if the option must be chosen by default
	IsDefault bool
}

// StarGiveawayWinnerOptionTypeID is TL type id of StarGiveawayWinnerOption.
const StarGiveawayWinnerOptionTypeID = 0xcc639607

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

func (s *StarGiveawayWinnerOption) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.WinnerCount == 0) {
		return false
	}
	if !(s.WonStarCount == 0) {
		return false
	}
	if !(s.IsDefault == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StarGiveawayWinnerOption) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "starGiveawayWinnerOption",
		ID:   StarGiveawayWinnerOptionTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "WinnerCount",
			SchemaName: "winner_count",
		},
		{
			Name:       "WonStarCount",
			SchemaName: "won_star_count",
		},
		{
			Name:       "IsDefault",
			SchemaName: "is_default",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StarGiveawayWinnerOption) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiveawayWinnerOption#cc639607 as nil")
	}
	b.PutID(StarGiveawayWinnerOptionTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StarGiveawayWinnerOption) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiveawayWinnerOption#cc639607 as nil")
	}
	b.PutInt32(s.WinnerCount)
	b.PutInt53(s.WonStarCount)
	b.PutBool(s.IsDefault)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *StarGiveawayWinnerOption) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiveawayWinnerOption#cc639607 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: field winner_count: %w", err)
		}
		s.WinnerCount = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: field won_star_count: %w", err)
		}
		s.WonStarCount = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: field is_default: %w", err)
		}
		s.IsDefault = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StarGiveawayWinnerOption) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode starGiveawayWinnerOption#cc639607 as nil")
	}
	b.ObjStart()
	b.PutID("starGiveawayWinnerOption")
	b.Comma()
	b.FieldStart("winner_count")
	b.PutInt32(s.WinnerCount)
	b.Comma()
	b.FieldStart("won_star_count")
	b.PutInt53(s.WonStarCount)
	b.Comma()
	b.FieldStart("is_default")
	b.PutBool(s.IsDefault)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StarGiveawayWinnerOption) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode starGiveawayWinnerOption#cc639607 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("starGiveawayWinnerOption"); err != nil {
				return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: %w", err)
			}
		case "winner_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: field winner_count: %w", err)
			}
			s.WinnerCount = value
		case "won_star_count":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: field won_star_count: %w", err)
			}
			s.WonStarCount = value
		case "is_default":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode starGiveawayWinnerOption#cc639607: field is_default: %w", err)
			}
			s.IsDefault = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetWinnerCount returns value of WinnerCount field.
func (s *StarGiveawayWinnerOption) GetWinnerCount() (value int32) {
	if s == nil {
		return
	}
	return s.WinnerCount
}

// GetWonStarCount returns value of WonStarCount field.
func (s *StarGiveawayWinnerOption) GetWonStarCount() (value int64) {
	if s == nil {
		return
	}
	return s.WonStarCount
}

// GetIsDefault returns value of IsDefault field.
func (s *StarGiveawayWinnerOption) GetIsDefault() (value bool) {
	if s == nil {
		return
	}
	return s.IsDefault
}
