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

// TodoList represents TL type `todoList#49b92a26`.
// Represents a todo list »¹.
//
// Links:
//  1. https://core.telegram.org/api/todo
//
// See https://core.telegram.org/constructor/todoList for reference.
type TodoList struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, users different from the creator of the list can append items to the list.
	OthersCanAppend bool
	// If set, users different from the creator of the list can complete items in the list.
	OthersCanComplete bool
	// Title of the todo list, maximum length equal to todo_title_length_max »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/config#todo-title-length-max
	Title TextWithEntities
	// Items of the list.
	List []TodoItem
}

// TodoListTypeID is TL type id of TodoList.
const TodoListTypeID = 0x49b92a26

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

func ( *TodoList) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.OthersCanAppend == false) {
		return false
	}
	if !(.OthersCanComplete == false) {
		return false
	}
	if !(.Title.Zero()) {
		return false
	}
	if !(.List == nil) {
		return false
	}

	return true
}

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

// FillFrom fills TodoList from given interface.
func ( *TodoList) ( interface {
	() ( bool)
	() ( bool)
	() ( TextWithEntities)
	() ( []TodoItem)
}) {
	.OthersCanAppend = .()
	.OthersCanComplete = .()
	.Title = .()
	.List = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *TodoList) () tdp.Type {
	 := tdp.Type{
		Name: "todoList",
		ID:   TodoListTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "OthersCanAppend",
			SchemaName: "others_can_append",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "OthersCanComplete",
			SchemaName: "others_can_complete",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "List",
			SchemaName: "list",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *TodoList) () {
	if !(.OthersCanAppend == false) {
		.Flags.Set(0)
	}
	if !(.OthersCanComplete == false) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *TodoList) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode todoList#49b92a26 as nil")
	}
	.PutID(TodoListTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *TodoList) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode todoList#49b92a26 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode todoList#49b92a26: field flags: %w", )
	}
	if  := .Title.Encode();  != nil {
		return fmt.Errorf("unable to encode todoList#49b92a26: field title: %w", )
	}
	.PutVectorHeader(len(.List))
	for ,  := range .List {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode todoList#49b92a26: field list element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *TodoList) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode todoList#49b92a26 to nil")
	}
	if  := .ConsumeID(TodoListTypeID);  != nil {
		return fmt.Errorf("unable to decode todoList#49b92a26: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *TodoList) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode todoList#49b92a26 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode todoList#49b92a26: field flags: %w", )
		}
	}
	.OthersCanAppend = .Flags.Has(0)
	.OthersCanComplete = .Flags.Has(1)
	{
		if  := .Title.Decode();  != nil {
			return fmt.Errorf("unable to decode todoList#49b92a26: field title: %w", )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode todoList#49b92a26: field list: %w", )
		}

		if  > 0 {
			.List = make([]TodoItem, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  TodoItem
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode todoList#49b92a26: field list: %w", )
			}
			.List = append(.List, )
		}
	}
	return nil
}

// SetOthersCanAppend sets value of OthersCanAppend conditional field.
func ( *TodoList) ( bool) {
	if  {
		.Flags.Set(0)
		.OthersCanAppend = true
	} else {
		.Flags.Unset(0)
		.OthersCanAppend = false
	}
}

// GetOthersCanAppend returns value of OthersCanAppend conditional field.
func ( *TodoList) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetOthersCanComplete sets value of OthersCanComplete conditional field.
func ( *TodoList) ( bool) {
	if  {
		.Flags.Set(1)
		.OthersCanComplete = true
	} else {
		.Flags.Unset(1)
		.OthersCanComplete = false
	}
}

// GetOthersCanComplete returns value of OthersCanComplete conditional field.
func ( *TodoList) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetTitle returns value of Title field.
func ( *TodoList) () ( TextWithEntities) {
	if  == nil {
		return
	}
	return .Title
}

// GetList returns value of List field.
func ( *TodoList) () ( []TodoItem) {
	if  == nil {
		return
	}
	return .List
}