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

// SetBusinessAwayMessageSettingsRequest represents TL type `setBusinessAwayMessageSettings#4974486c`.
type SetBusinessAwayMessageSettingsRequest struct {
	// The new settings for the away message of the business; pass null to disable the away
	// message
	AwayMessageSettings BusinessAwayMessageSettings
}

// SetBusinessAwayMessageSettingsRequestTypeID is TL type id of SetBusinessAwayMessageSettingsRequest.
const SetBusinessAwayMessageSettingsRequestTypeID = 0x4974486c

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

func (s *SetBusinessAwayMessageSettingsRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.AwayMessageSettings.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetBusinessAwayMessageSettingsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setBusinessAwayMessageSettings",
		ID:   SetBusinessAwayMessageSettingsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "AwayMessageSettings",
			SchemaName: "away_message_settings",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetBusinessAwayMessageSettingsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAwayMessageSettings#4974486c as nil")
	}
	b.PutID(SetBusinessAwayMessageSettingsRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetBusinessAwayMessageSettingsRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAwayMessageSettings#4974486c as nil")
	}
	if err := s.AwayMessageSettings.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setBusinessAwayMessageSettings#4974486c: field away_message_settings: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SetBusinessAwayMessageSettingsRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAwayMessageSettings#4974486c to nil")
	}
	if err := b.ConsumeID(SetBusinessAwayMessageSettingsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setBusinessAwayMessageSettings#4974486c: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetBusinessAwayMessageSettingsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAwayMessageSettings#4974486c to nil")
	}
	{
		if err := s.AwayMessageSettings.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setBusinessAwayMessageSettings#4974486c: field away_message_settings: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetBusinessAwayMessageSettingsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAwayMessageSettings#4974486c as nil")
	}
	b.ObjStart()
	b.PutID("setBusinessAwayMessageSettings")
	b.Comma()
	b.FieldStart("away_message_settings")
	if err := s.AwayMessageSettings.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setBusinessAwayMessageSettings#4974486c: field away_message_settings: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetBusinessAwayMessageSettingsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAwayMessageSettings#4974486c to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setBusinessAwayMessageSettings"); err != nil {
				return fmt.Errorf("unable to decode setBusinessAwayMessageSettings#4974486c: %w", err)
			}
		case "away_message_settings":
			if err := s.AwayMessageSettings.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode setBusinessAwayMessageSettings#4974486c: field away_message_settings: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetAwayMessageSettings returns value of AwayMessageSettings field.
func (s *SetBusinessAwayMessageSettingsRequest) GetAwayMessageSettings() (value BusinessAwayMessageSettings) {
	if s == nil {
		return
	}
	return s.AwayMessageSettings
}

// SetBusinessAwayMessageSettings invokes method setBusinessAwayMessageSettings#4974486c returning error if any.
func (c *Client) SetBusinessAwayMessageSettings(ctx context.Context, awaymessagesettings BusinessAwayMessageSettings) error {
	var ok Ok

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