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

// BusinessBotRights represents TL type `businessBotRights#49018f7e`.
type BusinessBotRights struct {
	// True, if the bot can send and edit messages in the private chats that had incoming
	// messages in the last 24 hours
	CanReply bool
	// True, if the bot can mark incoming private messages as read
	CanReadMessages bool
	// True, if the bot can delete sent messages
	CanDeleteSentMessages bool
	// True, if the bot can delete any message
	CanDeleteAllMessages bool
	// True, if the bot can edit name of the business account
	CanEditName bool
	// True, if the bot can edit bio of the business account
	CanEditBio bool
	// True, if the bot can edit profile photo of the business account
	CanEditProfilePhoto bool
	// True, if the bot can edit username of the business account
	CanEditUsername bool
	// True, if the bot can view gifts and amount of Telegram Stars owned by the business
	// account
	CanViewGiftsAndStars bool
	// True, if the bot can sell regular gifts received by the business account
	CanSellGifts bool
	// True, if the bot can change gift receiving settings of the business account
	CanChangeGiftSettings bool
	// True, if the bot can transfer and upgrade gifts received by the business account
	CanTransferAndUpgradeGifts bool
	// True, if the bot can transfer Telegram Stars received by the business account to
	// account of the bot, or use them to upgrade and transfer gifts
	CanTransferStars bool
	// True, if the bot can post, edit and delete stories
	CanManageStories bool
}

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

// 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.CanReply == false) {
		return false
	}
	if !(b.CanReadMessages == false) {
		return false
	}
	if !(b.CanDeleteSentMessages == false) {
		return false
	}
	if !(b.CanDeleteAllMessages == false) {
		return false
	}
	if !(b.CanEditName == false) {
		return false
	}
	if !(b.CanEditBio == false) {
		return false
	}
	if !(b.CanEditProfilePhoto == false) {
		return false
	}
	if !(b.CanEditUsername == false) {
		return false
	}
	if !(b.CanViewGiftsAndStars == false) {
		return false
	}
	if !(b.CanSellGifts == false) {
		return false
	}
	if !(b.CanChangeGiftSettings == false) {
		return false
	}
	if !(b.CanTransferAndUpgradeGifts == false) {
		return false
	}
	if !(b.CanTransferStars == false) {
		return false
	}
	if !(b.CanManageStories == 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))
}

// 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:       "CanReply",
			SchemaName: "can_reply",
		},
		{
			Name:       "CanReadMessages",
			SchemaName: "can_read_messages",
		},
		{
			Name:       "CanDeleteSentMessages",
			SchemaName: "can_delete_sent_messages",
		},
		{
			Name:       "CanDeleteAllMessages",
			SchemaName: "can_delete_all_messages",
		},
		{
			Name:       "CanEditName",
			SchemaName: "can_edit_name",
		},
		{
			Name:       "CanEditBio",
			SchemaName: "can_edit_bio",
		},
		{
			Name:       "CanEditProfilePhoto",
			SchemaName: "can_edit_profile_photo",
		},
		{
			Name:       "CanEditUsername",
			SchemaName: "can_edit_username",
		},
		{
			Name:       "CanViewGiftsAndStars",
			SchemaName: "can_view_gifts_and_stars",
		},
		{
			Name:       "CanSellGifts",
			SchemaName: "can_sell_gifts",
		},
		{
			Name:       "CanChangeGiftSettings",
			SchemaName: "can_change_gift_settings",
		},
		{
			Name:       "CanTransferAndUpgradeGifts",
			SchemaName: "can_transfer_and_upgrade_gifts",
		},
		{
			Name:       "CanTransferStars",
			SchemaName: "can_transfer_stars",
		},
		{
			Name:       "CanManageStories",
			SchemaName: "can_manage_stories",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (b *BusinessBotRights) Encode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't encode businessBotRights#49018f7e 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#49018f7e as nil")
	}
	buf.PutBool(b.CanReply)
	buf.PutBool(b.CanReadMessages)
	buf.PutBool(b.CanDeleteSentMessages)
	buf.PutBool(b.CanDeleteAllMessages)
	buf.PutBool(b.CanEditName)
	buf.PutBool(b.CanEditBio)
	buf.PutBool(b.CanEditProfilePhoto)
	buf.PutBool(b.CanEditUsername)
	buf.PutBool(b.CanViewGiftsAndStars)
	buf.PutBool(b.CanSellGifts)
	buf.PutBool(b.CanChangeGiftSettings)
	buf.PutBool(b.CanTransferAndUpgradeGifts)
	buf.PutBool(b.CanTransferStars)
	buf.PutBool(b.CanManageStories)
	return nil
}

// Decode implements bin.Decoder.
func (b *BusinessBotRights) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("can't decode businessBotRights#49018f7e to nil")
	}
	if err := buf.ConsumeID(BusinessBotRightsTypeID); err != nil {
		return fmt.Errorf("unable to decode businessBotRights#49018f7e: %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#49018f7e to nil")
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_reply: %w", err)
		}
		b.CanReply = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_read_messages: %w", err)
		}
		b.CanReadMessages = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_delete_sent_messages: %w", err)
		}
		b.CanDeleteSentMessages = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_delete_all_messages: %w", err)
		}
		b.CanDeleteAllMessages = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_name: %w", err)
		}
		b.CanEditName = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_bio: %w", err)
		}
		b.CanEditBio = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_profile_photo: %w", err)
		}
		b.CanEditProfilePhoto = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_username: %w", err)
		}
		b.CanEditUsername = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_view_gifts_and_stars: %w", err)
		}
		b.CanViewGiftsAndStars = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_sell_gifts: %w", err)
		}
		b.CanSellGifts = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_change_gift_settings: %w", err)
		}
		b.CanChangeGiftSettings = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_transfer_and_upgrade_gifts: %w", err)
		}
		b.CanTransferAndUpgradeGifts = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_transfer_stars: %w", err)
		}
		b.CanTransferStars = value
	}
	{
		value, err := buf.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_manage_stories: %w", err)
		}
		b.CanManageStories = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (b *BusinessBotRights) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil {
		return fmt.Errorf("can't encode businessBotRights#49018f7e as nil")
	}
	buf.ObjStart()
	buf.PutID("businessBotRights")
	buf.Comma()
	buf.FieldStart("can_reply")
	buf.PutBool(b.CanReply)
	buf.Comma()
	buf.FieldStart("can_read_messages")
	buf.PutBool(b.CanReadMessages)
	buf.Comma()
	buf.FieldStart("can_delete_sent_messages")
	buf.PutBool(b.CanDeleteSentMessages)
	buf.Comma()
	buf.FieldStart("can_delete_all_messages")
	buf.PutBool(b.CanDeleteAllMessages)
	buf.Comma()
	buf.FieldStart("can_edit_name")
	buf.PutBool(b.CanEditName)
	buf.Comma()
	buf.FieldStart("can_edit_bio")
	buf.PutBool(b.CanEditBio)
	buf.Comma()
	buf.FieldStart("can_edit_profile_photo")
	buf.PutBool(b.CanEditProfilePhoto)
	buf.Comma()
	buf.FieldStart("can_edit_username")
	buf.PutBool(b.CanEditUsername)
	buf.Comma()
	buf.FieldStart("can_view_gifts_and_stars")
	buf.PutBool(b.CanViewGiftsAndStars)
	buf.Comma()
	buf.FieldStart("can_sell_gifts")
	buf.PutBool(b.CanSellGifts)
	buf.Comma()
	buf.FieldStart("can_change_gift_settings")
	buf.PutBool(b.CanChangeGiftSettings)
	buf.Comma()
	buf.FieldStart("can_transfer_and_upgrade_gifts")
	buf.PutBool(b.CanTransferAndUpgradeGifts)
	buf.Comma()
	buf.FieldStart("can_transfer_stars")
	buf.PutBool(b.CanTransferStars)
	buf.Comma()
	buf.FieldStart("can_manage_stories")
	buf.PutBool(b.CanManageStories)
	buf.Comma()
	buf.StripComma()
	buf.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (b *BusinessBotRights) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("can't decode businessBotRights#49018f7e to nil")
	}

	return buf.Obj(func(buf tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := buf.ConsumeID("businessBotRights"); err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: %w", err)
			}
		case "can_reply":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_reply: %w", err)
			}
			b.CanReply = value
		case "can_read_messages":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_read_messages: %w", err)
			}
			b.CanReadMessages = value
		case "can_delete_sent_messages":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_delete_sent_messages: %w", err)
			}
			b.CanDeleteSentMessages = value
		case "can_delete_all_messages":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_delete_all_messages: %w", err)
			}
			b.CanDeleteAllMessages = value
		case "can_edit_name":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_name: %w", err)
			}
			b.CanEditName = value
		case "can_edit_bio":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_bio: %w", err)
			}
			b.CanEditBio = value
		case "can_edit_profile_photo":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_profile_photo: %w", err)
			}
			b.CanEditProfilePhoto = value
		case "can_edit_username":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_edit_username: %w", err)
			}
			b.CanEditUsername = value
		case "can_view_gifts_and_stars":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_view_gifts_and_stars: %w", err)
			}
			b.CanViewGiftsAndStars = value
		case "can_sell_gifts":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_sell_gifts: %w", err)
			}
			b.CanSellGifts = value
		case "can_change_gift_settings":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_change_gift_settings: %w", err)
			}
			b.CanChangeGiftSettings = value
		case "can_transfer_and_upgrade_gifts":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_transfer_and_upgrade_gifts: %w", err)
			}
			b.CanTransferAndUpgradeGifts = value
		case "can_transfer_stars":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_transfer_stars: %w", err)
			}
			b.CanTransferStars = value
		case "can_manage_stories":
			value, err := buf.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode businessBotRights#49018f7e: field can_manage_stories: %w", err)
			}
			b.CanManageStories = value
		default:
			return buf.Skip()
		}
		return nil
	})
}

// GetCanReply returns value of CanReply field.
func (b *BusinessBotRights) GetCanReply() (value bool) {
	if b == nil {
		return
	}
	return b.CanReply
}

// GetCanReadMessages returns value of CanReadMessages field.
func (b *BusinessBotRights) GetCanReadMessages() (value bool) {
	if b == nil {
		return
	}
	return b.CanReadMessages
}

// GetCanDeleteSentMessages returns value of CanDeleteSentMessages field.
func (b *BusinessBotRights) GetCanDeleteSentMessages() (value bool) {
	if b == nil {
		return
	}
	return b.CanDeleteSentMessages
}

// GetCanDeleteAllMessages returns value of CanDeleteAllMessages field.
func (b *BusinessBotRights) GetCanDeleteAllMessages() (value bool) {
	if b == nil {
		return
	}
	return b.CanDeleteAllMessages
}

// GetCanEditName returns value of CanEditName field.
func (b *BusinessBotRights) GetCanEditName() (value bool) {
	if b == nil {
		return
	}
	return b.CanEditName
}

// GetCanEditBio returns value of CanEditBio field.
func (b *BusinessBotRights) GetCanEditBio() (value bool) {
	if b == nil {
		return
	}
	return b.CanEditBio
}

// GetCanEditProfilePhoto returns value of CanEditProfilePhoto field.
func (b *BusinessBotRights) GetCanEditProfilePhoto() (value bool) {
	if b == nil {
		return
	}
	return b.CanEditProfilePhoto
}

// GetCanEditUsername returns value of CanEditUsername field.
func (b *BusinessBotRights) GetCanEditUsername() (value bool) {
	if b == nil {
		return
	}
	return b.CanEditUsername
}

// GetCanViewGiftsAndStars returns value of CanViewGiftsAndStars field.
func (b *BusinessBotRights) GetCanViewGiftsAndStars() (value bool) {
	if b == nil {
		return
	}
	return b.CanViewGiftsAndStars
}

// GetCanSellGifts returns value of CanSellGifts field.
func (b *BusinessBotRights) GetCanSellGifts() (value bool) {
	if b == nil {
		return
	}
	return b.CanSellGifts
}

// GetCanChangeGiftSettings returns value of CanChangeGiftSettings field.
func (b *BusinessBotRights) GetCanChangeGiftSettings() (value bool) {
	if b == nil {
		return
	}
	return b.CanChangeGiftSettings
}

// GetCanTransferAndUpgradeGifts returns value of CanTransferAndUpgradeGifts field.
func (b *BusinessBotRights) GetCanTransferAndUpgradeGifts() (value bool) {
	if b == nil {
		return
	}
	return b.CanTransferAndUpgradeGifts
}

// GetCanTransferStars returns value of CanTransferStars field.
func (b *BusinessBotRights) GetCanTransferStars() (value bool) {
	if b == nil {
		return
	}
	return b.CanTransferStars
}

// GetCanManageStories returns value of CanManageStories field.
func (b *BusinessBotRights) GetCanManageStories() (value bool) {
	if b == nil {
		return
	}
	return b.CanManageStories
}
