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

// SetDefaultMessageAutoDeleteTimeRequest represents TL type `setDefaultMessageAutoDeleteTime#965cd36c`.
type SetDefaultMessageAutoDeleteTimeRequest struct {
	// New default message auto-delete time; must be from 0 up to 365 * 86400 and be
	// divisible by 86400. If 0, then messages aren't deleted automatically
	MessageAutoDeleteTime MessageAutoDeleteTime
}

// SetDefaultMessageAutoDeleteTimeRequestTypeID is TL type id of SetDefaultMessageAutoDeleteTimeRequest.
const SetDefaultMessageAutoDeleteTimeRequestTypeID = 0x965cd36c

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetDefaultMessageAutoDeleteTimeRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setDefaultMessageAutoDeleteTime",
		ID:   SetDefaultMessageAutoDeleteTimeRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "MessageAutoDeleteTime",
			SchemaName: "message_auto_delete_time",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetDefaultMessageAutoDeleteTimeRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setDefaultMessageAutoDeleteTime#965cd36c as nil")
	}
	b.PutID(SetDefaultMessageAutoDeleteTimeRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetDefaultMessageAutoDeleteTimeRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setDefaultMessageAutoDeleteTime#965cd36c as nil")
	}
	if err := s.MessageAutoDeleteTime.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setDefaultMessageAutoDeleteTime#965cd36c: field message_auto_delete_time: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SetDefaultMessageAutoDeleteTimeRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setDefaultMessageAutoDeleteTime#965cd36c to nil")
	}
	if err := b.ConsumeID(SetDefaultMessageAutoDeleteTimeRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setDefaultMessageAutoDeleteTime#965cd36c: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetDefaultMessageAutoDeleteTimeRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setDefaultMessageAutoDeleteTime#965cd36c to nil")
	}
	{
		if err := s.MessageAutoDeleteTime.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setDefaultMessageAutoDeleteTime#965cd36c: field message_auto_delete_time: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetDefaultMessageAutoDeleteTimeRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setDefaultMessageAutoDeleteTime#965cd36c as nil")
	}
	b.ObjStart()
	b.PutID("setDefaultMessageAutoDeleteTime")
	b.Comma()
	b.FieldStart("message_auto_delete_time")
	if err := s.MessageAutoDeleteTime.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setDefaultMessageAutoDeleteTime#965cd36c: field message_auto_delete_time: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetDefaultMessageAutoDeleteTimeRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setDefaultMessageAutoDeleteTime#965cd36c to nil")
	}

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

// GetMessageAutoDeleteTime returns value of MessageAutoDeleteTime field.
func (s *SetDefaultMessageAutoDeleteTimeRequest) GetMessageAutoDeleteTime() (value MessageAutoDeleteTime) {
	if s == nil {
		return
	}
	return s.MessageAutoDeleteTime
}

// SetDefaultMessageAutoDeleteTime invokes method setDefaultMessageAutoDeleteTime#965cd36c returning error if any.
func (c *Client) SetDefaultMessageAutoDeleteTime(ctx context.Context, messageautodeletetime MessageAutoDeleteTime) error {
	var ok Ok

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