// Code generated by gotdgen, DO NOT EDIT.

package td

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

// TestVectorBytes represents TL type `testVectorBytes#a590fb25`.
//
// See https://localhost:80/doc/constructor/testVectorBytes for reference.
type TestVectorBytes struct {
	// Value field of TestVectorBytes.
	Value [][]byte
}

// TestVectorBytesTypeID is TL type id of TestVectorBytes.
const TestVectorBytesTypeID = 0xa590fb25

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

func (t *TestVectorBytes) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.Value == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *TestVectorBytes) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "testVectorBytes",
		ID:   TestVectorBytesTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Value",
			SchemaName: "value",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *TestVectorBytes) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode testVectorBytes#a590fb25 as nil")
	}
	b.PutID(TestVectorBytesTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *TestVectorBytes) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode testVectorBytes#a590fb25 as nil")
	}
	b.PutInt(len(t.Value))
	for _, v := range t.Value {
		b.PutBytes(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (t *TestVectorBytes) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode testVectorBytes#a590fb25 to nil")
	}
	if err := b.ConsumeID(TestVectorBytesTypeID); err != nil {
		return fmt.Errorf("unable to decode testVectorBytes#a590fb25: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *TestVectorBytes) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode testVectorBytes#a590fb25 to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode testVectorBytes#a590fb25: field value: %w", err)
		}

		if headerLen > 0 {
			t.Value = make([][]byte, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Bytes()
			if err != nil {
				return fmt.Errorf("unable to decode testVectorBytes#a590fb25: field value: %w", err)
			}
			t.Value = append(t.Value, value)
		}
	}
	return nil
}

// GetValue returns value of Value field.
func (t *TestVectorBytes) GetValue() (value [][]byte) {
	if t == nil {
		return
	}
	return t.Value
}
