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

// SetFileGenerationProgressRequest represents TL type `setFileGenerationProgress#6d754b3e`.
type SetFileGenerationProgressRequest struct {
	// The identifier of the generation process
	GenerationID int64
	// Expected size of the generated file, in bytes; 0 if unknown
	ExpectedSize int64
	// The number of bytes already generated
	LocalPrefixSize int64
}

// SetFileGenerationProgressRequestTypeID is TL type id of SetFileGenerationProgressRequest.
const SetFileGenerationProgressRequestTypeID = 0x6d754b3e

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

func (s *SetFileGenerationProgressRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.GenerationID == 0) {
		return false
	}
	if !(s.ExpectedSize == 0) {
		return false
	}
	if !(s.LocalPrefixSize == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetFileGenerationProgressRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setFileGenerationProgress",
		ID:   SetFileGenerationProgressRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GenerationID",
			SchemaName: "generation_id",
		},
		{
			Name:       "ExpectedSize",
			SchemaName: "expected_size",
		},
		{
			Name:       "LocalPrefixSize",
			SchemaName: "local_prefix_size",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetFileGenerationProgressRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setFileGenerationProgress#6d754b3e as nil")
	}
	b.PutID(SetFileGenerationProgressRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetFileGenerationProgressRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setFileGenerationProgress#6d754b3e as nil")
	}
	b.PutLong(s.GenerationID)
	b.PutInt53(s.ExpectedSize)
	b.PutInt53(s.LocalPrefixSize)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetFileGenerationProgressRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setFileGenerationProgress#6d754b3e to nil")
	}
	if err := b.ConsumeID(SetFileGenerationProgressRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetFileGenerationProgressRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setFileGenerationProgress#6d754b3e to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: field generation_id: %w", err)
		}
		s.GenerationID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: field expected_size: %w", err)
		}
		s.ExpectedSize = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: field local_prefix_size: %w", err)
		}
		s.LocalPrefixSize = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetFileGenerationProgressRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setFileGenerationProgress#6d754b3e as nil")
	}
	b.ObjStart()
	b.PutID("setFileGenerationProgress")
	b.Comma()
	b.FieldStart("generation_id")
	b.PutLong(s.GenerationID)
	b.Comma()
	b.FieldStart("expected_size")
	b.PutInt53(s.ExpectedSize)
	b.Comma()
	b.FieldStart("local_prefix_size")
	b.PutInt53(s.LocalPrefixSize)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetFileGenerationProgressRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setFileGenerationProgress#6d754b3e to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setFileGenerationProgress"); err != nil {
				return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: %w", err)
			}
		case "generation_id":
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: field generation_id: %w", err)
			}
			s.GenerationID = value
		case "expected_size":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: field expected_size: %w", err)
			}
			s.ExpectedSize = value
		case "local_prefix_size":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setFileGenerationProgress#6d754b3e: field local_prefix_size: %w", err)
			}
			s.LocalPrefixSize = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetGenerationID returns value of GenerationID field.
func (s *SetFileGenerationProgressRequest) GetGenerationID() (value int64) {
	if s == nil {
		return
	}
	return s.GenerationID
}

// GetExpectedSize returns value of ExpectedSize field.
func (s *SetFileGenerationProgressRequest) GetExpectedSize() (value int64) {
	if s == nil {
		return
	}
	return s.ExpectedSize
}

// GetLocalPrefixSize returns value of LocalPrefixSize field.
func (s *SetFileGenerationProgressRequest) GetLocalPrefixSize() (value int64) {
	if s == nil {
		return
	}
	return s.LocalPrefixSize
}

// SetFileGenerationProgress invokes method setFileGenerationProgress#6d754b3e returning error if any.
func (c *Client) SetFileGenerationProgress(ctx context.Context, request *SetFileGenerationProgressRequest) error {
	var ok Ok

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