// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// MessagesDeleteHistoryRequest represents TL type `messages.deleteHistory#b08f922a`.
// Deletes communication history.
//
// See https://core.telegram.org/method/messages.deleteHistory for reference.
type MessagesDeleteHistoryRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Just clear history for the current user, without actually removing messages for every
	// chat user
	JustClear bool
	// Whether to delete the message history for all chat participants
	Revoke bool
	// User or chat, communication history of which will be deleted
	Peer InputPeerClass
	// Maximum ID of message to delete
	MaxID int
	// Delete all messages newer than this UNIX timestamp
	//
	// Use SetMinDate and GetMinDate helpers.
	MinDate int
	// Delete all messages older than this UNIX timestamp
	//
	// Use SetMaxDate and GetMaxDate helpers.
	MaxDate int
}

// MessagesDeleteHistoryRequestTypeID is TL type id of MessagesDeleteHistoryRequest.
const MessagesDeleteHistoryRequestTypeID = 0xb08f922a

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

func ( *MessagesDeleteHistoryRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.JustClear == false) {
		return false
	}
	if !(.Revoke == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.MaxID == 0) {
		return false
	}
	if !(.MinDate == 0) {
		return false
	}
	if !(.MaxDate == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesDeleteHistoryRequest from given interface.
func ( *MessagesDeleteHistoryRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputPeerClass)
	() ( int)
	() ( int,  bool)
	() ( int,  bool)
}) {
	.JustClear = .()
	.Revoke = .()
	.Peer = .()
	.MaxID = .()
	if ,  := .();  {
		.MinDate = 
	}

	if ,  := .();  {
		.MaxDate = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*MessagesDeleteHistoryRequest) () string {
	return "messages.deleteHistory"
}

// TypeInfo returns info about TL type.
func ( *MessagesDeleteHistoryRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.deleteHistory",
		ID:   MessagesDeleteHistoryRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "JustClear",
			SchemaName: "just_clear",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Revoke",
			SchemaName: "revoke",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "MaxID",
			SchemaName: "max_id",
		},
		{
			Name:       "MinDate",
			SchemaName: "min_date",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "MaxDate",
			SchemaName: "max_date",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesDeleteHistoryRequest) () {
	if !(.JustClear == false) {
		.Flags.Set(0)
	}
	if !(.Revoke == false) {
		.Flags.Set(1)
	}
	if !(.MinDate == 0) {
		.Flags.Set(2)
	}
	if !(.MaxDate == 0) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesDeleteHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.deleteHistory#b08f922a as nil")
	}
	.PutID(MessagesDeleteHistoryRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesDeleteHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.deleteHistory#b08f922a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.deleteHistory#b08f922a: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.deleteHistory#b08f922a: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.deleteHistory#b08f922a: field peer: %w", )
	}
	.PutInt(.MaxID)
	if .Flags.Has(2) {
		.PutInt(.MinDate)
	}
	if .Flags.Has(3) {
		.PutInt(.MaxDate)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesDeleteHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.deleteHistory#b08f922a to nil")
	}
	if  := .ConsumeID(MessagesDeleteHistoryRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.deleteHistory#b08f922a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesDeleteHistoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.deleteHistory#b08f922a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.deleteHistory#b08f922a: field flags: %w", )
		}
	}
	.JustClear = .Flags.Has(0)
	.Revoke = .Flags.Has(1)
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.deleteHistory#b08f922a: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.deleteHistory#b08f922a: field max_id: %w", )
		}
		.MaxID = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.deleteHistory#b08f922a: field min_date: %w", )
		}
		.MinDate = 
	}
	if .Flags.Has(3) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.deleteHistory#b08f922a: field max_date: %w", )
		}
		.MaxDate = 
	}
	return nil
}

// SetJustClear sets value of JustClear conditional field.
func ( *MessagesDeleteHistoryRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.JustClear = true
	} else {
		.Flags.Unset(0)
		.JustClear = false
	}
}

// GetJustClear returns value of JustClear conditional field.
func ( *MessagesDeleteHistoryRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetRevoke sets value of Revoke conditional field.
func ( *MessagesDeleteHistoryRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.Revoke = true
	} else {
		.Flags.Unset(1)
		.Revoke = false
	}
}

// GetRevoke returns value of Revoke conditional field.
func ( *MessagesDeleteHistoryRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetPeer returns value of Peer field.
func ( *MessagesDeleteHistoryRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// GetMaxID returns value of MaxID field.
func ( *MessagesDeleteHistoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .MaxID
}

// SetMinDate sets value of MinDate conditional field.
func ( *MessagesDeleteHistoryRequest) ( int) {
	.Flags.Set(2)
	.MinDate = 
}

// GetMinDate returns value of MinDate conditional field and
// boolean which is true if field was set.
func ( *MessagesDeleteHistoryRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .MinDate, true
}

// SetMaxDate sets value of MaxDate conditional field.
func ( *MessagesDeleteHistoryRequest) ( int) {
	.Flags.Set(3)
	.MaxDate = 
}

// GetMaxDate returns value of MaxDate conditional field and
// boolean which is true if field was set.
func ( *MessagesDeleteHistoryRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .MaxDate, true
}

// MessagesDeleteHistory invokes method messages.deleteHistory#b08f922a returning error if any.
// Deletes communication history.
//
// Possible errors:
//
//	400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	400 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	400 CHAT_ID_INVALID: The provided chat id is invalid.
//	400 CHAT_REVOKE_DATE_UNSUPPORTED: min_date and max_date are not available for using with non-user peers.
//	400 MAX_DATE_INVALID: The specified maximum date is invalid.
//	400 MESSAGE_ID_INVALID: The provided message id is invalid.
//	400 MIN_DATE_INVALID: The specified minimum date is invalid.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/messages.deleteHistory for reference.
func ( *Client) ( context.Context,  *MessagesDeleteHistoryRequest) (*MessagesAffectedHistory, error) {
	var  MessagesAffectedHistory

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return &, nil
}