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

// SetBusinessAccountGiftSettingsRequest represents TL type `setBusinessAccountGiftSettings#68c55612`.
type SetBusinessAccountGiftSettingsRequest struct {
	// Unique identifier of business connection
	BusinessConnectionID string
	// The new settings
	Settings GiftSettings
}

// SetBusinessAccountGiftSettingsRequestTypeID is TL type id of SetBusinessAccountGiftSettingsRequest.
const SetBusinessAccountGiftSettingsRequestTypeID = 0x68c55612

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetBusinessAccountGiftSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setBusinessAccountGiftSettings",
		ID:   SetBusinessAccountGiftSettingsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BusinessConnectionID",
			SchemaName: "business_connection_id",
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetBusinessAccountGiftSettingsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountGiftSettings#68c55612 as nil")
	}
	b.PutID(SetBusinessAccountGiftSettingsRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetBusinessAccountGiftSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountGiftSettings#68c55612 as nil")
	}
	b.PutString(s.BusinessConnectionID)
	if err := s.Settings.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setBusinessAccountGiftSettings#68c55612: field settings: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SetBusinessAccountGiftSettingsRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountGiftSettings#68c55612 to nil")
	}
	if err := b.ConsumeID(SetBusinessAccountGiftSettingsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setBusinessAccountGiftSettings#68c55612: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetBusinessAccountGiftSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountGiftSettings#68c55612 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountGiftSettings#68c55612: field business_connection_id: %w", err)
		}
		s.BusinessConnectionID = value
	}
	{
		if err := s.Settings.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountGiftSettings#68c55612: field settings: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetBusinessAccountGiftSettingsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountGiftSettings#68c55612 as nil")
	}
	b.ObjStart()
	b.PutID("setBusinessAccountGiftSettings")
	b.Comma()
	b.FieldStart("business_connection_id")
	b.PutString(s.BusinessConnectionID)
	b.Comma()
	b.FieldStart("settings")
	if err := s.Settings.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setBusinessAccountGiftSettings#68c55612: field settings: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetBusinessAccountGiftSettingsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountGiftSettings#68c55612 to nil")
	}

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

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

// GetSettings returns value of Settings field.
func (s *SetBusinessAccountGiftSettingsRequest) GetSettings() (value GiftSettings) {
	if s == nil {
		return
	}
	return s.Settings
}

// SetBusinessAccountGiftSettings invokes method setBusinessAccountGiftSettings#68c55612 returning error if any.
func (c *Client) SetBusinessAccountGiftSettings(ctx context.Context, request *SetBusinessAccountGiftSettingsRequest) error {
	var ok Ok

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