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

// SendCallDebugInformationRequest represents TL type `sendCallDebugInformation#785b373f`.
type SendCallDebugInformationRequest struct {
	// Call identifier
	CallID int32
	// Debug information in application-specific format
	DebugInformation string
}

// SendCallDebugInformationRequestTypeID is TL type id of SendCallDebugInformationRequest.
const SendCallDebugInformationRequestTypeID = 0x785b373f

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

func (s *SendCallDebugInformationRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.CallID == 0) {
		return false
	}
	if !(s.DebugInformation == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SendCallDebugInformationRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "sendCallDebugInformation",
		ID:   SendCallDebugInformationRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "CallID",
			SchemaName: "call_id",
		},
		{
			Name:       "DebugInformation",
			SchemaName: "debug_information",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SendCallDebugInformationRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sendCallDebugInformation#785b373f as nil")
	}
	b.PutID(SendCallDebugInformationRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SendCallDebugInformationRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode sendCallDebugInformation#785b373f as nil")
	}
	b.PutInt32(s.CallID)
	b.PutString(s.DebugInformation)
	return nil
}

// Decode implements bin.Decoder.
func (s *SendCallDebugInformationRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sendCallDebugInformation#785b373f to nil")
	}
	if err := b.ConsumeID(SendCallDebugInformationRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode sendCallDebugInformation#785b373f: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SendCallDebugInformationRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode sendCallDebugInformation#785b373f to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode sendCallDebugInformation#785b373f: field call_id: %w", err)
		}
		s.CallID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode sendCallDebugInformation#785b373f: field debug_information: %w", err)
		}
		s.DebugInformation = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SendCallDebugInformationRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode sendCallDebugInformation#785b373f as nil")
	}
	b.ObjStart()
	b.PutID("sendCallDebugInformation")
	b.Comma()
	b.FieldStart("call_id")
	b.PutInt32(s.CallID)
	b.Comma()
	b.FieldStart("debug_information")
	b.PutString(s.DebugInformation)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SendCallDebugInformationRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode sendCallDebugInformation#785b373f to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("sendCallDebugInformation"); err != nil {
				return fmt.Errorf("unable to decode sendCallDebugInformation#785b373f: %w", err)
			}
		case "call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode sendCallDebugInformation#785b373f: field call_id: %w", err)
			}
			s.CallID = value
		case "debug_information":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode sendCallDebugInformation#785b373f: field debug_information: %w", err)
			}
			s.DebugInformation = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetCallID returns value of CallID field.
func (s *SendCallDebugInformationRequest) GetCallID() (value int32) {
	if s == nil {
		return
	}
	return s.CallID
}

// GetDebugInformation returns value of DebugInformation field.
func (s *SendCallDebugInformationRequest) GetDebugInformation() (value string) {
	if s == nil {
		return
	}
	return s.DebugInformation
}

// SendCallDebugInformation invokes method sendCallDebugInformation#785b373f returning error if any.
func (c *Client) SendCallDebugInformation(ctx context.Context, request *SendCallDebugInformationRequest) error {
	var ok Ok

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