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

// DisallowedGiftsSettings represents TL type `disallowedGiftsSettings#71f276c4`.
// Disallow the reception of specific gift¹ types.
//
// Links:
//  1. https://core.telegram.org/api/gifts
//
// See https://core.telegram.org/constructor/disallowedGiftsSettings for reference.
type DisallowedGiftsSettings struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Disallow the reception of gifts with an unlimited supply (those with the starGift¹
	// limited flag not set).
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGift
	DisallowUnlimitedStargifts bool
	// Disallow the reception of limited-supply gifts (those with the starGift¹.limited flag
	// set).
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGift
	DisallowLimitedStargifts bool
	// Disallow the reception of collectible gifts »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#collectible-gifts
	DisallowUniqueStargifts bool
	// Disallow the reception of gifted Telegram Premium subscriptions »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#collectible-gifts
	DisallowPremiumGifts bool
	// DisallowStargiftsFromChannels field of DisallowedGiftsSettings.
	DisallowStargiftsFromChannels bool
}

// DisallowedGiftsSettingsTypeID is TL type id of DisallowedGiftsSettings.
const DisallowedGiftsSettingsTypeID = 0x71f276c4

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

func (d *DisallowedGiftsSettings) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.Flags.Zero()) {
		return false
	}
	if !(d.DisallowUnlimitedStargifts == false) {
		return false
	}
	if !(d.DisallowLimitedStargifts == false) {
		return false
	}
	if !(d.DisallowUniqueStargifts == false) {
		return false
	}
	if !(d.DisallowPremiumGifts == false) {
		return false
	}
	if !(d.DisallowStargiftsFromChannels == false) {
		return false
	}

	return true
}

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

// FillFrom fills DisallowedGiftsSettings from given interface.
func (d *DisallowedGiftsSettings) FillFrom(from interface {
	GetDisallowUnlimitedStargifts() (value bool)
	GetDisallowLimitedStargifts() (value bool)
	GetDisallowUniqueStargifts() (value bool)
	GetDisallowPremiumGifts() (value bool)
	GetDisallowStargiftsFromChannels() (value bool)
}) {
	d.DisallowUnlimitedStargifts = from.GetDisallowUnlimitedStargifts()
	d.DisallowLimitedStargifts = from.GetDisallowLimitedStargifts()
	d.DisallowUniqueStargifts = from.GetDisallowUniqueStargifts()
	d.DisallowPremiumGifts = from.GetDisallowPremiumGifts()
	d.DisallowStargiftsFromChannels = from.GetDisallowStargiftsFromChannels()
}

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

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

// TypeInfo returns info about TL type.
func (d *DisallowedGiftsSettings) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "disallowedGiftsSettings",
		ID:   DisallowedGiftsSettingsTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DisallowUnlimitedStargifts",
			SchemaName: "disallow_unlimited_stargifts",
			Null:       !d.Flags.Has(0),
		},
		{
			Name:       "DisallowLimitedStargifts",
			SchemaName: "disallow_limited_stargifts",
			Null:       !d.Flags.Has(1),
		},
		{
			Name:       "DisallowUniqueStargifts",
			SchemaName: "disallow_unique_stargifts",
			Null:       !d.Flags.Has(2),
		},
		{
			Name:       "DisallowPremiumGifts",
			SchemaName: "disallow_premium_gifts",
			Null:       !d.Flags.Has(3),
		},
		{
			Name:       "DisallowStargiftsFromChannels",
			SchemaName: "disallow_stargifts_from_channels",
			Null:       !d.Flags.Has(4),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (d *DisallowedGiftsSettings) SetFlags() {
	if !(d.DisallowUnlimitedStargifts == false) {
		d.Flags.Set(0)
	}
	if !(d.DisallowLimitedStargifts == false) {
		d.Flags.Set(1)
	}
	if !(d.DisallowUniqueStargifts == false) {
		d.Flags.Set(2)
	}
	if !(d.DisallowPremiumGifts == false) {
		d.Flags.Set(3)
	}
	if !(d.DisallowStargiftsFromChannels == false) {
		d.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func (d *DisallowedGiftsSettings) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode disallowedGiftsSettings#71f276c4 as nil")
	}
	b.PutID(DisallowedGiftsSettingsTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DisallowedGiftsSettings) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode disallowedGiftsSettings#71f276c4 as nil")
	}
	d.SetFlags()
	if err := d.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode disallowedGiftsSettings#71f276c4: field flags: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (d *DisallowedGiftsSettings) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode disallowedGiftsSettings#71f276c4 to nil")
	}
	if err := b.ConsumeID(DisallowedGiftsSettingsTypeID); err != nil {
		return fmt.Errorf("unable to decode disallowedGiftsSettings#71f276c4: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *DisallowedGiftsSettings) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode disallowedGiftsSettings#71f276c4 to nil")
	}
	{
		if err := d.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode disallowedGiftsSettings#71f276c4: field flags: %w", err)
		}
	}
	d.DisallowUnlimitedStargifts = d.Flags.Has(0)
	d.DisallowLimitedStargifts = d.Flags.Has(1)
	d.DisallowUniqueStargifts = d.Flags.Has(2)
	d.DisallowPremiumGifts = d.Flags.Has(3)
	d.DisallowStargiftsFromChannels = d.Flags.Has(4)
	return nil
}

// SetDisallowUnlimitedStargifts sets value of DisallowUnlimitedStargifts conditional field.
func (d *DisallowedGiftsSettings) SetDisallowUnlimitedStargifts(value bool) {
	if value {
		d.Flags.Set(0)
		d.DisallowUnlimitedStargifts = true
	} else {
		d.Flags.Unset(0)
		d.DisallowUnlimitedStargifts = false
	}
}

// GetDisallowUnlimitedStargifts returns value of DisallowUnlimitedStargifts conditional field.
func (d *DisallowedGiftsSettings) GetDisallowUnlimitedStargifts() (value bool) {
	if d == nil {
		return
	}
	return d.Flags.Has(0)
}

// SetDisallowLimitedStargifts sets value of DisallowLimitedStargifts conditional field.
func (d *DisallowedGiftsSettings) SetDisallowLimitedStargifts(value bool) {
	if value {
		d.Flags.Set(1)
		d.DisallowLimitedStargifts = true
	} else {
		d.Flags.Unset(1)
		d.DisallowLimitedStargifts = false
	}
}

// GetDisallowLimitedStargifts returns value of DisallowLimitedStargifts conditional field.
func (d *DisallowedGiftsSettings) GetDisallowLimitedStargifts() (value bool) {
	if d == nil {
		return
	}
	return d.Flags.Has(1)
}

// SetDisallowUniqueStargifts sets value of DisallowUniqueStargifts conditional field.
func (d *DisallowedGiftsSettings) SetDisallowUniqueStargifts(value bool) {
	if value {
		d.Flags.Set(2)
		d.DisallowUniqueStargifts = true
	} else {
		d.Flags.Unset(2)
		d.DisallowUniqueStargifts = false
	}
}

// GetDisallowUniqueStargifts returns value of DisallowUniqueStargifts conditional field.
func (d *DisallowedGiftsSettings) GetDisallowUniqueStargifts() (value bool) {
	if d == nil {
		return
	}
	return d.Flags.Has(2)
}

// SetDisallowPremiumGifts sets value of DisallowPremiumGifts conditional field.
func (d *DisallowedGiftsSettings) SetDisallowPremiumGifts(value bool) {
	if value {
		d.Flags.Set(3)
		d.DisallowPremiumGifts = true
	} else {
		d.Flags.Unset(3)
		d.DisallowPremiumGifts = false
	}
}

// GetDisallowPremiumGifts returns value of DisallowPremiumGifts conditional field.
func (d *DisallowedGiftsSettings) GetDisallowPremiumGifts() (value bool) {
	if d == nil {
		return
	}
	return d.Flags.Has(3)
}

// SetDisallowStargiftsFromChannels sets value of DisallowStargiftsFromChannels conditional field.
func (d *DisallowedGiftsSettings) SetDisallowStargiftsFromChannels(value bool) {
	if value {
		d.Flags.Set(4)
		d.DisallowStargiftsFromChannels = true
	} else {
		d.Flags.Unset(4)
		d.DisallowStargiftsFromChannels = false
	}
}

// GetDisallowStargiftsFromChannels returns value of DisallowStargiftsFromChannels conditional field.
func (d *DisallowedGiftsSettings) GetDisallowStargiftsFromChannels() (value bool) {
	if d == nil {
		return
	}
	return d.Flags.Has(4)
}
