//go:build !no_gotd_slices
// +build !no_gotd_slices

// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// InputSecureFileClassArray is adapter for slice of InputSecureFileClass.
type InputSecureFileClassArray []InputSecureFileClass

// Sort sorts slice of InputSecureFileClass.
func (s InputSecureFileClassArray) Sort(less func(a, b InputSecureFileClass) bool) InputSecureFileClassArray {
	sort.Slice(s, func(i, j int) bool {
		return less(s[i], s[j])
	})
	return s
}

// SortStable sorts slice of InputSecureFileClass.
func (s InputSecureFileClassArray) SortStable(less func(a, b InputSecureFileClass) bool) InputSecureFileClassArray {
	sort.SliceStable(s, func(i, j int) bool {
		return less(s[i], s[j])
	})
	return s
}

// Retain filters in-place slice of InputSecureFileClass.
func (s InputSecureFileClassArray) Retain(keep func(x InputSecureFileClass) bool) InputSecureFileClassArray {
	n := 0
	for _, x := range s {
		if keep(x) {
			s[n] = x
			n++
		}
	}
	s = s[:n]

	return s
}

// First returns first element of slice (if exists).
func (s InputSecureFileClassArray) First() (v InputSecureFileClass, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s InputSecureFileClassArray) Last() (v InputSecureFileClass, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[len(s)-1], true
}

// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputSecureFileClassArray) PopFirst() (v InputSecureFileClass, ok bool) {
	if s == nil || len(*s) < 1 {
		return
	}

	a := *s
	v = a[0]

	// Delete by index from SliceTricks.
	copy(a[0:], a[1:])
	var zero InputSecureFileClass
	a[len(a)-1] = zero
	a = a[:len(a)-1]
	*s = a

	return v, true
}

// Pop returns last element of slice (if exists) and deletes it.
func (s *InputSecureFileClassArray) Pop() (v InputSecureFileClass, ok bool) {
	if s == nil || len(*s) < 1 {
		return
	}

	a := *s
	v = a[len(a)-1]
	a = a[:len(a)-1]
	*s = a

	return v, true
}

// SortByID sorts slice of InputSecureFileClass by ID.
func (s InputSecureFileClassArray) SortByID() InputSecureFileClassArray {
	return s.Sort(func(a, b InputSecureFileClass) bool {
		return a.GetID() < b.GetID()
	})
}

// SortStableByID sorts slice of InputSecureFileClass by ID.
func (s InputSecureFileClassArray) SortStableByID() InputSecureFileClassArray {
	return s.SortStable(func(a, b InputSecureFileClass) bool {
		return a.GetID() < b.GetID()
	})
}

// FillInputSecureFileUploadedMap fills only InputSecureFileUploaded constructors to given map.
func (s InputSecureFileClassArray) FillInputSecureFileUploadedMap(to map[int64]*InputSecureFileUploaded) {
	for _, elem := range s {
		value, ok := elem.(*InputSecureFileUploaded)
		if !ok {
			continue
		}
		to[value.GetID()] = value
	}
}

// InputSecureFileUploadedToMap collects only InputSecureFileUploaded constructors to map.
func (s InputSecureFileClassArray) InputSecureFileUploadedToMap() map[int64]*InputSecureFileUploaded {
	r := make(map[int64]*InputSecureFileUploaded, len(s))
	s.FillInputSecureFileUploadedMap(r)
	return r
}

// AsInputSecureFileUploaded returns copy with only InputSecureFileUploaded constructors.
func (s InputSecureFileClassArray) AsInputSecureFileUploaded() (to InputSecureFileUploadedArray) {
	for _, elem := range s {
		value, ok := elem.(*InputSecureFileUploaded)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// FillInputSecureFileMap fills only InputSecureFile constructors to given map.
func (s InputSecureFileClassArray) FillInputSecureFileMap(to map[int64]*InputSecureFile) {
	for _, elem := range s {
		value, ok := elem.(*InputSecureFile)
		if !ok {
			continue
		}
		to[value.GetID()] = value
	}
}

// InputSecureFileToMap collects only InputSecureFile constructors to map.
func (s InputSecureFileClassArray) InputSecureFileToMap() map[int64]*InputSecureFile {
	r := make(map[int64]*InputSecureFile, len(s))
	s.FillInputSecureFileMap(r)
	return r
}

// AsInputSecureFile returns copy with only InputSecureFile constructors.
func (s InputSecureFileClassArray) AsInputSecureFile() (to InputSecureFileArray) {
	for _, elem := range s {
		value, ok := elem.(*InputSecureFile)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// InputSecureFileUploadedArray is adapter for slice of InputSecureFileUploaded.
type InputSecureFileUploadedArray []InputSecureFileUploaded

// Sort sorts slice of InputSecureFileUploaded.
func (s InputSecureFileUploadedArray) Sort(less func(a, b InputSecureFileUploaded) bool) InputSecureFileUploadedArray {
	sort.Slice(s, func(i, j int) bool {
		return less(s[i], s[j])
	})
	return s
}

// SortStable sorts slice of InputSecureFileUploaded.
func (s InputSecureFileUploadedArray) SortStable(less func(a, b InputSecureFileUploaded) bool) InputSecureFileUploadedArray {
	sort.SliceStable(s, func(i, j int) bool {
		return less(s[i], s[j])
	})
	return s
}

// Retain filters in-place slice of InputSecureFileUploaded.
func (s InputSecureFileUploadedArray) Retain(keep func(x InputSecureFileUploaded) bool) InputSecureFileUploadedArray {
	n := 0
	for _, x := range s {
		if keep(x) {
			s[n] = x
			n++
		}
	}
	s = s[:n]

	return s
}

// First returns first element of slice (if exists).
func (s InputSecureFileUploadedArray) First() (v InputSecureFileUploaded, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s InputSecureFileUploadedArray) Last() (v InputSecureFileUploaded, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[len(s)-1], true
}

// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputSecureFileUploadedArray) PopFirst() (v InputSecureFileUploaded, ok bool) {
	if s == nil || len(*s) < 1 {
		return
	}

	a := *s
	v = a[0]

	// Delete by index from SliceTricks.
	copy(a[0:], a[1:])
	var zero InputSecureFileUploaded
	a[len(a)-1] = zero
	a = a[:len(a)-1]
	*s = a

	return v, true
}

// Pop returns last element of slice (if exists) and deletes it.
func (s *InputSecureFileUploadedArray) Pop() (v InputSecureFileUploaded, ok bool) {
	if s == nil || len(*s) < 1 {
		return
	}

	a := *s
	v = a[len(a)-1]
	a = a[:len(a)-1]
	*s = a

	return v, true
}

// SortByID sorts slice of InputSecureFileUploaded by ID.
func (s InputSecureFileUploadedArray) SortByID() InputSecureFileUploadedArray {
	return s.Sort(func(a, b InputSecureFileUploaded) bool {
		return a.GetID() < b.GetID()
	})
}

// SortStableByID sorts slice of InputSecureFileUploaded by ID.
func (s InputSecureFileUploadedArray) SortStableByID() InputSecureFileUploadedArray {
	return s.SortStable(func(a, b InputSecureFileUploaded) bool {
		return a.GetID() < b.GetID()
	})
}

// FillMap fills constructors to given map.
func (s InputSecureFileUploadedArray) FillMap(to map[int64]InputSecureFileUploaded) {
	for _, value := range s {
		to[value.GetID()] = value
	}
}

// ToMap collects constructors to map.
func (s InputSecureFileUploadedArray) ToMap() map[int64]InputSecureFileUploaded {
	r := make(map[int64]InputSecureFileUploaded, len(s))
	s.FillMap(r)
	return r
}

// InputSecureFileArray is adapter for slice of InputSecureFile.
type InputSecureFileArray []InputSecureFile

// Sort sorts slice of InputSecureFile.
func (s InputSecureFileArray) Sort(less func(a, b InputSecureFile) bool) InputSecureFileArray {
	sort.Slice(s, func(i, j int) bool {
		return less(s[i], s[j])
	})
	return s
}

// SortStable sorts slice of InputSecureFile.
func (s InputSecureFileArray) SortStable(less func(a, b InputSecureFile) bool) InputSecureFileArray {
	sort.SliceStable(s, func(i, j int) bool {
		return less(s[i], s[j])
	})
	return s
}

// Retain filters in-place slice of InputSecureFile.
func (s InputSecureFileArray) Retain(keep func(x InputSecureFile) bool) InputSecureFileArray {
	n := 0
	for _, x := range s {
		if keep(x) {
			s[n] = x
			n++
		}
	}
	s = s[:n]

	return s
}

// First returns first element of slice (if exists).
func (s InputSecureFileArray) First() (v InputSecureFile, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s InputSecureFileArray) Last() (v InputSecureFile, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[len(s)-1], true
}

// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputSecureFileArray) PopFirst() (v InputSecureFile, ok bool) {
	if s == nil || len(*s) < 1 {
		return
	}

	a := *s
	v = a[0]

	// Delete by index from SliceTricks.
	copy(a[0:], a[1:])
	var zero InputSecureFile
	a[len(a)-1] = zero
	a = a[:len(a)-1]
	*s = a

	return v, true
}

// Pop returns last element of slice (if exists) and deletes it.
func (s *InputSecureFileArray) Pop() (v InputSecureFile, ok bool) {
	if s == nil || len(*s) < 1 {
		return
	}

	a := *s
	v = a[len(a)-1]
	a = a[:len(a)-1]
	*s = a

	return v, true
}

// SortByID sorts slice of InputSecureFile by ID.
func (s InputSecureFileArray) SortByID() InputSecureFileArray {
	return s.Sort(func(a, b InputSecureFile) bool {
		return a.GetID() < b.GetID()
	})
}

// SortStableByID sorts slice of InputSecureFile by ID.
func (s InputSecureFileArray) SortStableByID() InputSecureFileArray {
	return s.SortStable(func(a, b InputSecureFile) bool {
		return a.GetID() < b.GetID()
	})
}

// FillMap fills constructors to given map.
func (s InputSecureFileArray) FillMap(to map[int64]InputSecureFile) {
	for _, value := range s {
		to[value.GetID()] = value
	}
}

// ToMap collects constructors to map.
func (s InputSecureFileArray) ToMap() map[int64]InputSecureFile {
	r := make(map[int64]InputSecureFile, len(s))
	s.FillMap(r)
	return r
}
