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

// SetBusinessAccountBioRequest represents TL type `setBusinessAccountBio#9ac25dc7`.
type SetBusinessAccountBioRequest struct {
	// Unique identifier of business connection
	BusinessConnectionID string
	// The new value of the bio; 0-getOption("bio_length_max") characters without line feeds
	Bio string
}

// SetBusinessAccountBioRequestTypeID is TL type id of SetBusinessAccountBioRequest.
const SetBusinessAccountBioRequestTypeID = 0x9ac25dc7

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

func (s *SetBusinessAccountBioRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.BusinessConnectionID == "") {
		return false
	}
	if !(s.Bio == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetBusinessAccountBioRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setBusinessAccountBio",
		ID:   SetBusinessAccountBioRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BusinessConnectionID",
			SchemaName: "business_connection_id",
		},
		{
			Name:       "Bio",
			SchemaName: "bio",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetBusinessAccountBioRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountBio#9ac25dc7 as nil")
	}
	b.PutID(SetBusinessAccountBioRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetBusinessAccountBioRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountBio#9ac25dc7 as nil")
	}
	b.PutString(s.BusinessConnectionID)
	b.PutString(s.Bio)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetBusinessAccountBioRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountBio#9ac25dc7 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountBio#9ac25dc7: field business_connection_id: %w", err)
		}
		s.BusinessConnectionID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountBio#9ac25dc7: field bio: %w", err)
		}
		s.Bio = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetBusinessAccountBioRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountBio#9ac25dc7 as nil")
	}
	b.ObjStart()
	b.PutID("setBusinessAccountBio")
	b.Comma()
	b.FieldStart("business_connection_id")
	b.PutString(s.BusinessConnectionID)
	b.Comma()
	b.FieldStart("bio")
	b.PutString(s.Bio)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setBusinessAccountBio"); err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountBio#9ac25dc7: %w", err)
			}
		case "business_connection_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountBio#9ac25dc7: field business_connection_id: %w", err)
			}
			s.BusinessConnectionID = value
		case "bio":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountBio#9ac25dc7: field bio: %w", err)
			}
			s.Bio = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

// GetBio returns value of Bio field.
func (s *SetBusinessAccountBioRequest) GetBio() (value string) {
	if s == nil {
		return
	}
	return s.Bio
}

// SetBusinessAccountBio invokes method setBusinessAccountBio#9ac25dc7 returning error if any.
func (c *Client) SetBusinessAccountBio(ctx context.Context, request *SetBusinessAccountBioRequest) error {
	var ok Ok

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