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

// BusinessBotRights represents TL type `businessBotRights#a0624cf7`.
// Business bot rights¹.
//
// Links:
//  1. https://core.telegram.org/api/bots/connected-business-bots
//
// See https://core.telegram.org/constructor/businessBotRights for reference.
type BusinessBotRights struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the bot can send and edit messages in private chats that had incoming messages
	// in the last 24 hours.
	Reply bool
	// Whether the bot can mark incoming private messages as read.
	ReadMessages bool
	// Whether the bot can delete messages sent by the bot.
	DeleteSentMessages bool
	// Whether the bot can delete received private messages in managed chats.
	DeleteReceivedMessages bool
	// Whether the bot can edit the first and last name of the business account.
	EditName bool
	// Whether the bot can edit the bio of the business account.
	EditBio bool
	// Whether the bot can edit the profile photo of the business account.
	EditProfilePhoto bool
	// Whether the bot can edit the username of the business account.
	EditUsername bool
	// Whether the bot can view gifts and the amount of Telegram Stars owned by the business
	// account.
	ViewGifts bool
	// Whether the bot can convert regular gifts owned by the business account to Telegram
	// Stars.
	SellGifts bool
	// Whether the bot can change the privacy settings pertaining to gifts for the business
	// account.
	ChangeGiftSettings bool
	// Whether the bot can transfer and upgrade gifts owned by the business account.
	TransferAndUpgradeGifts bool
	// Whether the bot can transfer Telegram Stars received by the business account to its
	// own account, or use them to upgrade and transfer gifts.
	TransferStars bool
	// Whether the bot can post, edit and delete stories on behalf of the business account.
	ManageStories bool
}

// BusinessBotRightsTypeID is TL type id of BusinessBotRights.
const BusinessBotRightsTypeID = 0xa0624cf7

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

func (b *BusinessBotRights) Zero() bool {
	if b == nil {
		return true
	}
	if !(b.Flags.Zero()) {
		return false
	}
	if !(b.Reply == false) {
		return false
	}
	if !(b.ReadMessages == false) {
		return false
	}
	if !(b.DeleteSentMessages == false) {
		return false
	}
	if !(b.DeleteReceivedMessages == false) {
		return false
	}
	if !(b.EditName == false) {
		return false
	}
	if !(b.EditBio == false) {
		return false
	}
	if !(b.EditProfilePhoto == false) {
		return false
	}
	if !(b.EditUsername == false) {
		return false
	}
	if !(b.ViewGifts == false) {
		return false
	}
	if !(b.SellGifts == false) {
		return false
	}
	if !(b.ChangeGiftSettings == false) {
		return false
	}
	if !(b.TransferAndUpgradeGifts == false) {
		return false
	}
	if !(b.TransferStars == false) {
		return false
	}
	if !(b.ManageStories == false) {
		return false
	}

	return true
}

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

// FillFrom fills BusinessBotRights from given interface.
func (b *BusinessBotRights) FillFrom(from interface {
	GetReply() (value bool)
	GetReadMessages() (value bool)
	GetDeleteSentMessages() (value bool)
	GetDeleteReceivedMessages() (value bool)
	GetEditName() (value bool)
	GetEditBio() (value bool)
	GetEditProfilePhoto() (value bool)
	GetEditUsername() (value bool)
	GetViewGifts() (value bool)
	GetSellGifts() (value bool)
	GetChangeGiftSettings() (value bool)
	GetTransferAndUpgradeGifts() (value bool)
	GetTransferStars() (value bool)
	GetManageStories() (value bool)
}) {
	b.Reply = from.GetReply()
	b.ReadMessages = from.GetReadMessages()
	b.DeleteSentMessages = from.GetDeleteSentMessages()
	b.DeleteReceivedMessages = from.GetDeleteReceivedMessages()
	b.EditName = from.GetEditName()
	b.EditBio = from.GetEditBio()
	b.EditProfilePhoto = from.GetEditProfilePhoto()
	b.EditUsername = from.GetEditUsername()
	b.ViewGifts = from.GetViewGifts()
	b.SellGifts = from.GetSellGifts()
	b.ChangeGiftSettings = from.GetChangeGiftSettings()
	b.TransferAndUpgradeGifts = from.GetTransferAndUpgradeGifts()
	b.TransferStars = from.GetTransferStars()
	b.ManageStories = from.GetManageStories()
}

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

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

// TypeInfo returns info about TL type.
func (b *BusinessBotRights) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "businessBotRights",
		ID:   BusinessBotRightsTypeID,
	}
	if b == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Reply",
			SchemaName: "reply",
			Null:       !b.Flags.Has(0),
		},
		{
			Name:       "ReadMessages",
			SchemaName: "read_messages",
			Null:       !b.Flags.Has(1),
		},
		{
			Name:       "DeleteSentMessages",
			SchemaName: "delete_sent_messages",
			Null:       !b.Flags.Has(2),
		},
		{
			Name:       "DeleteReceivedMessages",
			SchemaName: "delete_received_messages",
			Null:       !b.Flags.Has(3),
		},
		{
			Name:       "EditName",
			SchemaName: "edit_name",
			Null:       !b.Flags.Has(4),
		},
		{
			Name:       "EditBio",
			SchemaName: "edit_bio",
			Null:       !b.Flags.Has(5),
		},
		{
			Name:       "EditProfilePhoto",
			SchemaName: "edit_profile_photo",
			Null:       !b.Flags.Has(6),
		},
		{
			Name:       "EditUsername",
			SchemaName: "edit_username",
			Null:       !b.Flags.Has(7),
		},
		{
			Name:       "ViewGifts",
			SchemaName: "view_gifts",
			Null:       !b.Flags.Has(8),
		},
		{
			Name:       "SellGifts",
			SchemaName: "sell_gifts",
			Null:       !b.Flags.Has(9),
		},
		{
			Name:       "ChangeGiftSettings",
			SchemaName: "change_gift_settings",
			Null:       !b.Flags.Has(10),
		},
		{
			Name:       "TransferAndUpgradeGifts",
			SchemaName: "transfer_and_upgrade_gifts",
			Null:       !b.Flags.Has(11),
		},
		{
			Name:       "TransferStars",
			SchemaName: "transfer_stars",
			Null:       !b.Flags.Has(12),
		},
		{
			Name:       "ManageStories",
			SchemaName: "manage_stories",
			Null:       !b.Flags.Has(13),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (b *BusinessBotRights) SetFlags() {
	if !(b.Reply == false) {
		b.Flags.Set(0)
	}
	if !(b.ReadMessages == false) {
		b.Flags.Set(1)
	}
	if !(b.DeleteSentMessages == false) {
		b.Flags.Set(2)
	}
	if !(b.DeleteReceivedMessages == false) {
		b.Flags.Set(3)
	}
	if !(b.EditName == false) {
		b.Flags.Set(4)
	}
	if !(b.EditBio == false) {
		b.Flags.Set(5)
	}
	if !(b.EditProfilePhoto == false) {
		b.Flags.Set(6)
	}
	if !(b.EditUsername == false) {
		b.Flags.Set(7)
	}
	if !(b.ViewGifts == false) {
		b.Flags.Set(8)
	}
	if !(b.SellGifts == false) {
		b.Flags.Set(9)
	}
	if !(b.ChangeGiftSettings == false) {
		b.Flags.Set(10)
	}
	if !(b.TransferAndUpgradeGifts == false) {
		b.Flags.Set(11)
	}
	if !(b.TransferStars == false) {
		b.Flags.Set(12)
	}
	if !(b.ManageStories == false) {
		b.Flags.Set(13)
	}
}

// Encode implements bin.Encoder.
func (b *BusinessBotRights) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode businessBotRights#a0624cf7 as nil")
	}
	buf.PutID(BusinessBotRightsTypeID)
	return b.EncodeBare(buf)
}

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

// Decode implements bin.Decoder.
func (b *BusinessBotRights) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode businessBotRights#a0624cf7 to nil")
	}
	if err := buf.ConsumeID(BusinessBotRightsTypeID); err != nil {
		return fmt.Errorf("unable to decode businessBotRights#a0624cf7: %w", err)
	}
	return b.DecodeBare(buf)
}

// DecodeBare implements bin.BareDecoder.
func (b *BusinessBotRights) DecodeBare(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode businessBotRights#a0624cf7 to nil")
	}
	{
		if err := b.Flags.Decode(buf); err != nil {
			return fmt.Errorf("unable to decode businessBotRights#a0624cf7: field flags: %w", err)
		}
	}
	b.Reply = b.Flags.Has(0)
	b.ReadMessages = b.Flags.Has(1)
	b.DeleteSentMessages = b.Flags.Has(2)
	b.DeleteReceivedMessages = b.Flags.Has(3)
	b.EditName = b.Flags.Has(4)
	b.EditBio = b.Flags.Has(5)
	b.EditProfilePhoto = b.Flags.Has(6)
	b.EditUsername = b.Flags.Has(7)
	b.ViewGifts = b.Flags.Has(8)
	b.SellGifts = b.Flags.Has(9)
	b.ChangeGiftSettings = b.Flags.Has(10)
	b.TransferAndUpgradeGifts = b.Flags.Has(11)
	b.TransferStars = b.Flags.Has(12)
	b.ManageStories = b.Flags.Has(13)
	return nil
}

// SetReply sets value of Reply conditional field.
func (b *BusinessBotRights) SetReply(value bool) {
	if value {
		b.Flags.Set(0)
		b.Reply = true
	} else {
		b.Flags.Unset(0)
		b.Reply = false
	}
}

// GetReply returns value of Reply conditional field.
func (b *BusinessBotRights) GetReply() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(0)
}

// SetReadMessages sets value of ReadMessages conditional field.
func (b *BusinessBotRights) SetReadMessages(value bool) {
	if value {
		b.Flags.Set(1)
		b.ReadMessages = true
	} else {
		b.Flags.Unset(1)
		b.ReadMessages = false
	}
}

// GetReadMessages returns value of ReadMessages conditional field.
func (b *BusinessBotRights) GetReadMessages() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(1)
}

// SetDeleteSentMessages sets value of DeleteSentMessages conditional field.
func (b *BusinessBotRights) SetDeleteSentMessages(value bool) {
	if value {
		b.Flags.Set(2)
		b.DeleteSentMessages = true
	} else {
		b.Flags.Unset(2)
		b.DeleteSentMessages = false
	}
}

// GetDeleteSentMessages returns value of DeleteSentMessages conditional field.
func (b *BusinessBotRights) GetDeleteSentMessages() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(2)
}

// SetDeleteReceivedMessages sets value of DeleteReceivedMessages conditional field.
func (b *BusinessBotRights) SetDeleteReceivedMessages(value bool) {
	if value {
		b.Flags.Set(3)
		b.DeleteReceivedMessages = true
	} else {
		b.Flags.Unset(3)
		b.DeleteReceivedMessages = false
	}
}

// GetDeleteReceivedMessages returns value of DeleteReceivedMessages conditional field.
func (b *BusinessBotRights) GetDeleteReceivedMessages() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(3)
}

// SetEditName sets value of EditName conditional field.
func (b *BusinessBotRights) SetEditName(value bool) {
	if value {
		b.Flags.Set(4)
		b.EditName = true
	} else {
		b.Flags.Unset(4)
		b.EditName = false
	}
}

// GetEditName returns value of EditName conditional field.
func (b *BusinessBotRights) GetEditName() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(4)
}

// SetEditBio sets value of EditBio conditional field.
func (b *BusinessBotRights) SetEditBio(value bool) {
	if value {
		b.Flags.Set(5)
		b.EditBio = true
	} else {
		b.Flags.Unset(5)
		b.EditBio = false
	}
}

// GetEditBio returns value of EditBio conditional field.
func (b *BusinessBotRights) GetEditBio() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(5)
}

// SetEditProfilePhoto sets value of EditProfilePhoto conditional field.
func (b *BusinessBotRights) SetEditProfilePhoto(value bool) {
	if value {
		b.Flags.Set(6)
		b.EditProfilePhoto = true
	} else {
		b.Flags.Unset(6)
		b.EditProfilePhoto = false
	}
}

// GetEditProfilePhoto returns value of EditProfilePhoto conditional field.
func (b *BusinessBotRights) GetEditProfilePhoto() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(6)
}

// SetEditUsername sets value of EditUsername conditional field.
func (b *BusinessBotRights) SetEditUsername(value bool) {
	if value {
		b.Flags.Set(7)
		b.EditUsername = true
	} else {
		b.Flags.Unset(7)
		b.EditUsername = false
	}
}

// GetEditUsername returns value of EditUsername conditional field.
func (b *BusinessBotRights) GetEditUsername() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(7)
}

// SetViewGifts sets value of ViewGifts conditional field.
func (b *BusinessBotRights) SetViewGifts(value bool) {
	if value {
		b.Flags.Set(8)
		b.ViewGifts = true
	} else {
		b.Flags.Unset(8)
		b.ViewGifts = false
	}
}

// GetViewGifts returns value of ViewGifts conditional field.
func (b *BusinessBotRights) GetViewGifts() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(8)
}

// SetSellGifts sets value of SellGifts conditional field.
func (b *BusinessBotRights) SetSellGifts(value bool) {
	if value {
		b.Flags.Set(9)
		b.SellGifts = true
	} else {
		b.Flags.Unset(9)
		b.SellGifts = false
	}
}

// GetSellGifts returns value of SellGifts conditional field.
func (b *BusinessBotRights) GetSellGifts() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(9)
}

// SetChangeGiftSettings sets value of ChangeGiftSettings conditional field.
func (b *BusinessBotRights) SetChangeGiftSettings(value bool) {
	if value {
		b.Flags.Set(10)
		b.ChangeGiftSettings = true
	} else {
		b.Flags.Unset(10)
		b.ChangeGiftSettings = false
	}
}

// GetChangeGiftSettings returns value of ChangeGiftSettings conditional field.
func (b *BusinessBotRights) GetChangeGiftSettings() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(10)
}

// SetTransferAndUpgradeGifts sets value of TransferAndUpgradeGifts conditional field.
func (b *BusinessBotRights) SetTransferAndUpgradeGifts(value bool) {
	if value {
		b.Flags.Set(11)
		b.TransferAndUpgradeGifts = true
	} else {
		b.Flags.Unset(11)
		b.TransferAndUpgradeGifts = false
	}
}

// GetTransferAndUpgradeGifts returns value of TransferAndUpgradeGifts conditional field.
func (b *BusinessBotRights) GetTransferAndUpgradeGifts() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(11)
}

// SetTransferStars sets value of TransferStars conditional field.
func (b *BusinessBotRights) SetTransferStars(value bool) {
	if value {
		b.Flags.Set(12)
		b.TransferStars = true
	} else {
		b.Flags.Unset(12)
		b.TransferStars = false
	}
}

// GetTransferStars returns value of TransferStars conditional field.
func (b *BusinessBotRights) GetTransferStars() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(12)
}

// SetManageStories sets value of ManageStories conditional field.
func (b *BusinessBotRights) SetManageStories(value bool) {
	if value {
		b.Flags.Set(13)
		b.ManageStories = true
	} else {
		b.Flags.Unset(13)
		b.ManageStories = false
	}
}

// GetManageStories returns value of ManageStories conditional field.
func (b *BusinessBotRights) GetManageStories() (value bool) {
	if b == nil {
		return
	}
	return b.Flags.Has(13)
}
