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

// DeleteDirectMessagesChatTopicMessagesByDateRequest represents TL type `deleteDirectMessagesChatTopicMessagesByDate#3854ca09`.
type DeleteDirectMessagesChatTopicMessagesByDateRequest struct {
	// Chat identifier of the channel direct messages chat
	ChatID int64
	// Identifier of the topic which messages will be deleted
	TopicID int64
	// The minimum date of the messages to delete
	MinDate int32
	// The maximum date of the messages to delete
	MaxDate int32
}

// DeleteDirectMessagesChatTopicMessagesByDateRequestTypeID is TL type id of DeleteDirectMessagesChatTopicMessagesByDateRequest.
const DeleteDirectMessagesChatTopicMessagesByDateRequestTypeID = 0x3854ca09

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

func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.ChatID == 0) {
		return false
	}
	if !(d.TopicID == 0) {
		return false
	}
	if !(d.MinDate == 0) {
		return false
	}
	if !(d.MaxDate == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "deleteDirectMessagesChatTopicMessagesByDate",
		ID:   DeleteDirectMessagesChatTopicMessagesByDateRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "TopicID",
			SchemaName: "topic_id",
		},
		{
			Name:       "MinDate",
			SchemaName: "min_date",
		},
		{
			Name:       "MaxDate",
			SchemaName: "max_date",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteDirectMessagesChatTopicMessagesByDate#3854ca09 as nil")
	}
	b.PutID(DeleteDirectMessagesChatTopicMessagesByDateRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteDirectMessagesChatTopicMessagesByDate#3854ca09 as nil")
	}
	b.PutInt53(d.ChatID)
	b.PutInt53(d.TopicID)
	b.PutInt32(d.MinDate)
	b.PutInt32(d.MaxDate)
	return nil
}

// Decode implements bin.Decoder.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09 to nil")
	}
	if err := b.ConsumeID(DeleteDirectMessagesChatTopicMessagesByDateRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field chat_id: %w", err)
		}
		d.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field topic_id: %w", err)
		}
		d.TopicID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field min_date: %w", err)
		}
		d.MinDate = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field max_date: %w", err)
		}
		d.MaxDate = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteDirectMessagesChatTopicMessagesByDate#3854ca09 as nil")
	}
	b.ObjStart()
	b.PutID("deleteDirectMessagesChatTopicMessagesByDate")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(d.ChatID)
	b.Comma()
	b.FieldStart("topic_id")
	b.PutInt53(d.TopicID)
	b.Comma()
	b.FieldStart("min_date")
	b.PutInt32(d.MinDate)
	b.Comma()
	b.FieldStart("max_date")
	b.PutInt32(d.MaxDate)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("deleteDirectMessagesChatTopicMessagesByDate"); err != nil {
				return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field chat_id: %w", err)
			}
			d.ChatID = value
		case "topic_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field topic_id: %w", err)
			}
			d.TopicID = value
		case "min_date":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field min_date: %w", err)
			}
			d.MinDate = value
		case "max_date":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode deleteDirectMessagesChatTopicMessagesByDate#3854ca09: field max_date: %w", err)
			}
			d.MaxDate = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) GetChatID() (value int64) {
	if d == nil {
		return
	}
	return d.ChatID
}

// GetTopicID returns value of TopicID field.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) GetTopicID() (value int64) {
	if d == nil {
		return
	}
	return d.TopicID
}

// GetMinDate returns value of MinDate field.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) GetMinDate() (value int32) {
	if d == nil {
		return
	}
	return d.MinDate
}

// GetMaxDate returns value of MaxDate field.
func (d *DeleteDirectMessagesChatTopicMessagesByDateRequest) GetMaxDate() (value int32) {
	if d == nil {
		return
	}
	return d.MaxDate
}

// DeleteDirectMessagesChatTopicMessagesByDate invokes method deleteDirectMessagesChatTopicMessagesByDate#3854ca09 returning error if any.
func (c *Client) DeleteDirectMessagesChatTopicMessagesByDate(ctx context.Context, request *DeleteDirectMessagesChatTopicMessagesByDateRequest) error {
	var ok Ok

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