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

// TransferBusinessAccountStarsRequest represents TL type `transferBusinessAccountStars#2baa0420`.
type TransferBusinessAccountStarsRequest struct {
	// Unique identifier of business connection
	BusinessConnectionID string
	// Number of Telegram Stars to transfer
	StarCount int64
}

// TransferBusinessAccountStarsRequestTypeID is TL type id of TransferBusinessAccountStarsRequest.
const TransferBusinessAccountStarsRequestTypeID = 0x2baa0420

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

func (t *TransferBusinessAccountStarsRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.BusinessConnectionID == "") {
		return false
	}
	if !(t.StarCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TransferBusinessAccountStarsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "transferBusinessAccountStars",
		ID:   TransferBusinessAccountStarsRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BusinessConnectionID",
			SchemaName: "business_connection_id",
		},
		{
			Name:       "StarCount",
			SchemaName: "star_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TransferBusinessAccountStarsRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode transferBusinessAccountStars#2baa0420 as nil")
	}
	b.PutID(TransferBusinessAccountStarsRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TransferBusinessAccountStarsRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode transferBusinessAccountStars#2baa0420 as nil")
	}
	b.PutString(t.BusinessConnectionID)
	b.PutInt53(t.StarCount)
	return nil
}

// Decode implements bin.Decoder.
func (t *TransferBusinessAccountStarsRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode transferBusinessAccountStars#2baa0420 to nil")
	}
	if err := b.ConsumeID(TransferBusinessAccountStarsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode transferBusinessAccountStars#2baa0420: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *TransferBusinessAccountStarsRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode transferBusinessAccountStars#2baa0420 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode transferBusinessAccountStars#2baa0420: field business_connection_id: %w", err)
		}
		t.BusinessConnectionID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode transferBusinessAccountStars#2baa0420: field star_count: %w", err)
		}
		t.StarCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TransferBusinessAccountStarsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode transferBusinessAccountStars#2baa0420 as nil")
	}
	b.ObjStart()
	b.PutID("transferBusinessAccountStars")
	b.Comma()
	b.FieldStart("business_connection_id")
	b.PutString(t.BusinessConnectionID)
	b.Comma()
	b.FieldStart("star_count")
	b.PutInt53(t.StarCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TransferBusinessAccountStarsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if t == nil {
		return fmt.Errorf("can't decode transferBusinessAccountStars#2baa0420 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("transferBusinessAccountStars"); err != nil {
				return fmt.Errorf("unable to decode transferBusinessAccountStars#2baa0420: %w", err)
			}
		case "business_connection_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode transferBusinessAccountStars#2baa0420: field business_connection_id: %w", err)
			}
			t.BusinessConnectionID = value
		case "star_count":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode transferBusinessAccountStars#2baa0420: field star_count: %w", err)
			}
			t.StarCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBusinessConnectionID returns value of BusinessConnectionID field.
func (t *TransferBusinessAccountStarsRequest) GetBusinessConnectionID() (value string) {
	if t == nil {
		return
	}
	return t.BusinessConnectionID
}

// GetStarCount returns value of StarCount field.
func (t *TransferBusinessAccountStarsRequest) GetStarCount() (value int64) {
	if t == nil {
		return
	}
	return t.StarCount
}

// TransferBusinessAccountStars invokes method transferBusinessAccountStars#2baa0420 returning error if any.
func (c *Client) TransferBusinessAccountStars(ctx context.Context, request *TransferBusinessAccountStarsRequest) error {
	var ok Ok

	if err := c.rpc.Invoke(ctx, request, &ok); err != nil {
		return err
	}
	return nil
}
