//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"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// ChannelParticipantsFilterClassArray is adapter for slice of ChannelParticipantsFilterClass.
type ChannelParticipantsFilterClassArray []ChannelParticipantsFilterClass

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

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

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

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

// AsChannelParticipantsKicked returns copy with only ChannelParticipantsKicked constructors.
func (s ChannelParticipantsFilterClassArray) AsChannelParticipantsKicked() (to ChannelParticipantsKickedArray) {
	for _, elem := range s {
		value, ok := elem.(*ChannelParticipantsKicked)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsChannelParticipantsBanned returns copy with only ChannelParticipantsBanned constructors.
func (s ChannelParticipantsFilterClassArray) AsChannelParticipantsBanned() (to ChannelParticipantsBannedArray) {
	for _, elem := range s {
		value, ok := elem.(*ChannelParticipantsBanned)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsChannelParticipantsSearch returns copy with only ChannelParticipantsSearch constructors.
func (s ChannelParticipantsFilterClassArray) AsChannelParticipantsSearch() (to ChannelParticipantsSearchArray) {
	for _, elem := range s {
		value, ok := elem.(*ChannelParticipantsSearch)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsChannelParticipantsContacts returns copy with only ChannelParticipantsContacts constructors.
func (s ChannelParticipantsFilterClassArray) AsChannelParticipantsContacts() (to ChannelParticipantsContactsArray) {
	for _, elem := range s {
		value, ok := elem.(*ChannelParticipantsContacts)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsChannelParticipantsMentions returns copy with only ChannelParticipantsMentions constructors.
func (s ChannelParticipantsFilterClassArray) AsChannelParticipantsMentions() (to ChannelParticipantsMentionsArray) {
	for _, elem := range s {
		value, ok := elem.(*ChannelParticipantsMentions)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// ChannelParticipantsKickedArray is adapter for slice of ChannelParticipantsKicked.
type ChannelParticipantsKickedArray []ChannelParticipantsKicked

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

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

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

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

// ChannelParticipantsBannedArray is adapter for slice of ChannelParticipantsBanned.
type ChannelParticipantsBannedArray []ChannelParticipantsBanned

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

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

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

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

// ChannelParticipantsSearchArray is adapter for slice of ChannelParticipantsSearch.
type ChannelParticipantsSearchArray []ChannelParticipantsSearch

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

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

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

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

// ChannelParticipantsContactsArray is adapter for slice of ChannelParticipantsContacts.
type ChannelParticipantsContactsArray []ChannelParticipantsContacts

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

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

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

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

// ChannelParticipantsMentionsArray is adapter for slice of ChannelParticipantsMentions.
type ChannelParticipantsMentionsArray []ChannelParticipantsMentions

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

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

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

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