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

// StickerSetCoveredClassArray is adapter for slice of StickerSetCoveredClass.
type StickerSetCoveredClassArray []StickerSetCoveredClass

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

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

// Retain filters in-place slice of StickerSetCoveredClass.
func (s StickerSetCoveredClassArray) Retain(keep func(x StickerSetCoveredClass) bool) StickerSetCoveredClassArray {
	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 StickerSetCoveredClassArray) First() (v StickerSetCoveredClass, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s StickerSetCoveredClassArray) Last() (v StickerSetCoveredClass, 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 *StickerSetCoveredClassArray) PopFirst() (v StickerSetCoveredClass, 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 StickerSetCoveredClass
	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 *StickerSetCoveredClassArray) Pop() (v StickerSetCoveredClass, 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
}

// AsStickerSetCovered returns copy with only StickerSetCovered constructors.
func (s StickerSetCoveredClassArray) AsStickerSetCovered() (to StickerSetCoveredArray) {
	for _, elem := range s {
		value, ok := elem.(*StickerSetCovered)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsStickerSetMultiCovered returns copy with only StickerSetMultiCovered constructors.
func (s StickerSetCoveredClassArray) AsStickerSetMultiCovered() (to StickerSetMultiCoveredArray) {
	for _, elem := range s {
		value, ok := elem.(*StickerSetMultiCovered)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsStickerSetFullCovered returns copy with only StickerSetFullCovered constructors.
func (s StickerSetCoveredClassArray) AsStickerSetFullCovered() (to StickerSetFullCoveredArray) {
	for _, elem := range s {
		value, ok := elem.(*StickerSetFullCovered)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsStickerSetNoCovered returns copy with only StickerSetNoCovered constructors.
func (s StickerSetCoveredClassArray) AsStickerSetNoCovered() (to StickerSetNoCoveredArray) {
	for _, elem := range s {
		value, ok := elem.(*StickerSetNoCovered)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// StickerSetCoveredArray is adapter for slice of StickerSetCovered.
type StickerSetCoveredArray []StickerSetCovered

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

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

// Retain filters in-place slice of StickerSetCovered.
func (s StickerSetCoveredArray) Retain(keep func(x StickerSetCovered) bool) StickerSetCoveredArray {
	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 StickerSetCoveredArray) First() (v StickerSetCovered, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s StickerSetCoveredArray) Last() (v StickerSetCovered, 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 *StickerSetCoveredArray) PopFirst() (v StickerSetCovered, 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 StickerSetCovered
	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 *StickerSetCoveredArray) Pop() (v StickerSetCovered, 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
}

// StickerSetMultiCoveredArray is adapter for slice of StickerSetMultiCovered.
type StickerSetMultiCoveredArray []StickerSetMultiCovered

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

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

// Retain filters in-place slice of StickerSetMultiCovered.
func (s StickerSetMultiCoveredArray) Retain(keep func(x StickerSetMultiCovered) bool) StickerSetMultiCoveredArray {
	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 StickerSetMultiCoveredArray) First() (v StickerSetMultiCovered, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s StickerSetMultiCoveredArray) Last() (v StickerSetMultiCovered, 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 *StickerSetMultiCoveredArray) PopFirst() (v StickerSetMultiCovered, 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 StickerSetMultiCovered
	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 *StickerSetMultiCoveredArray) Pop() (v StickerSetMultiCovered, 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
}

// StickerSetFullCoveredArray is adapter for slice of StickerSetFullCovered.
type StickerSetFullCoveredArray []StickerSetFullCovered

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

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

// Retain filters in-place slice of StickerSetFullCovered.
func (s StickerSetFullCoveredArray) Retain(keep func(x StickerSetFullCovered) bool) StickerSetFullCoveredArray {
	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 StickerSetFullCoveredArray) First() (v StickerSetFullCovered, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s StickerSetFullCoveredArray) Last() (v StickerSetFullCovered, 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 *StickerSetFullCoveredArray) PopFirst() (v StickerSetFullCovered, 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 StickerSetFullCovered
	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 *StickerSetFullCoveredArray) Pop() (v StickerSetFullCovered, 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
}

// StickerSetNoCoveredArray is adapter for slice of StickerSetNoCovered.
type StickerSetNoCoveredArray []StickerSetNoCovered

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

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

// Retain filters in-place slice of StickerSetNoCovered.
func (s StickerSetNoCoveredArray) Retain(keep func(x StickerSetNoCovered) bool) StickerSetNoCoveredArray {
	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 StickerSetNoCoveredArray) First() (v StickerSetNoCovered, ok bool) {
	if len(s) < 1 {
		return
	}
	return s[0], true
}

// Last returns last element of slice (if exists).
func (s StickerSetNoCoveredArray) Last() (v StickerSetNoCovered, 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 *StickerSetNoCoveredArray) PopFirst() (v StickerSetNoCovered, 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 StickerSetNoCovered
	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 *StickerSetNoCoveredArray) Pop() (v StickerSetNoCovered, 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
}
