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

// PhoneDiscardCallRequest represents TL type `phone.discardCall#b2cbc1c0`.
// Refuse or end running call
//
// See https://core.telegram.org/method/phone.discardCall for reference.
type PhoneDiscardCallRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this is a video call
	Video bool
	// The phone call
	Peer InputPhoneCall
	// Call duration
	Duration int
	// Why was the call discarded
	Reason PhoneCallDiscardReasonClass
	// Preferred libtgvoip relay ID
	ConnectionID int64
}

// PhoneDiscardCallRequestTypeID is TL type id of PhoneDiscardCallRequest.
const PhoneDiscardCallRequestTypeID = 0xb2cbc1c0

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

func ( *PhoneDiscardCallRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Video == false) {
		return false
	}
	if !(.Peer.Zero()) {
		return false
	}
	if !(.Duration == 0) {
		return false
	}
	if !(.Reason == nil) {
		return false
	}
	if !(.ConnectionID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneDiscardCallRequest from given interface.
func ( *PhoneDiscardCallRequest) ( interface {
	() ( bool)
	() ( InputPhoneCall)
	() ( int)
	() ( PhoneCallDiscardReasonClass)
	() ( int64)
}) {
	.Video = .()
	.Peer = .()
	.Duration = .()
	.Reason = .()
	.ConnectionID = .()
}

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

// TypeName returns name of type in TL schema.
func (*PhoneDiscardCallRequest) () string {
	return "phone.discardCall"
}

// TypeInfo returns info about TL type.
func ( *PhoneDiscardCallRequest) () tdp.Type {
	 := tdp.Type{
		Name: "phone.discardCall",
		ID:   PhoneDiscardCallRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Video",
			SchemaName: "video",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Duration",
			SchemaName: "duration",
		},
		{
			Name:       "Reason",
			SchemaName: "reason",
		},
		{
			Name:       "ConnectionID",
			SchemaName: "connection_id",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PhoneDiscardCallRequest) () {
	if !(.Video == false) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *PhoneDiscardCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phone.discardCall#b2cbc1c0 as nil")
	}
	.PutID(PhoneDiscardCallRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhoneDiscardCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode phone.discardCall#b2cbc1c0 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.discardCall#b2cbc1c0: field flags: %w", )
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.discardCall#b2cbc1c0: field peer: %w", )
	}
	.PutInt(.Duration)
	if .Reason == nil {
		return fmt.Errorf("unable to encode phone.discardCall#b2cbc1c0: field reason is nil")
	}
	if  := .Reason.Encode();  != nil {
		return fmt.Errorf("unable to encode phone.discardCall#b2cbc1c0: field reason: %w", )
	}
	.PutLong(.ConnectionID)
	return nil
}

// Decode implements bin.Decoder.
func ( *PhoneDiscardCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phone.discardCall#b2cbc1c0 to nil")
	}
	if  := .ConsumeID(PhoneDiscardCallRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode phone.discardCall#b2cbc1c0: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PhoneDiscardCallRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode phone.discardCall#b2cbc1c0 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode phone.discardCall#b2cbc1c0: field flags: %w", )
		}
	}
	.Video = .Flags.Has(0)
	{
		if  := .Peer.Decode();  != nil {
			return fmt.Errorf("unable to decode phone.discardCall#b2cbc1c0: field peer: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode phone.discardCall#b2cbc1c0: field duration: %w", )
		}
		.Duration = 
	}
	{
		,  := DecodePhoneCallDiscardReason()
		if  != nil {
			return fmt.Errorf("unable to decode phone.discardCall#b2cbc1c0: field reason: %w", )
		}
		.Reason = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode phone.discardCall#b2cbc1c0: field connection_id: %w", )
		}
		.ConnectionID = 
	}
	return nil
}

// SetVideo sets value of Video conditional field.
func ( *PhoneDiscardCallRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Video = true
	} else {
		.Flags.Unset(0)
		.Video = false
	}
}

// GetVideo returns value of Video conditional field.
func ( *PhoneDiscardCallRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

// GetDuration returns value of Duration field.
func ( *PhoneDiscardCallRequest) () ( int) {
	if  == nil {
		return
	}
	return .Duration
}

// GetReason returns value of Reason field.
func ( *PhoneDiscardCallRequest) () ( PhoneCallDiscardReasonClass) {
	if  == nil {
		return
	}
	return .Reason
}

// GetConnectionID returns value of ConnectionID field.
func ( *PhoneDiscardCallRequest) () ( int64) {
	if  == nil {
		return
	}
	return .ConnectionID
}

// PhoneDiscardCall invokes method phone.discardCall#b2cbc1c0 returning error if any.
// Refuse or end running call
//
// Possible errors:
//
//	400 CALL_ALREADY_ACCEPTED: The call was already accepted.
//	500 CALL_OCCUPY_FAILED: The call failed because the user is already making another call.
//	400 CALL_PEER_INVALID: The provided call peer object is invalid.
//
// See https://core.telegram.org/method/phone.discardCall for reference.
func ( *Client) ( context.Context,  *PhoneDiscardCallRequest) (UpdatesClass, error) {
	var  UpdatesBox

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