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

// InputPasskeyCredentialClassArray is adapter for slice of InputPasskeyCredentialClass.
type InputPasskeyCredentialClassArray []InputPasskeyCredentialClass

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

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

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

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

// AsInputPasskeyCredentialPublicKey returns copy with only InputPasskeyCredentialPublicKey constructors.
func (s InputPasskeyCredentialClassArray) AsInputPasskeyCredentialPublicKey() (to InputPasskeyCredentialPublicKeyArray) {
	for _, elem := range s {
		value, ok := elem.(*InputPasskeyCredentialPublicKey)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsInputPasskeyCredentialFirebasePNV returns copy with only InputPasskeyCredentialFirebasePNV constructors.
func (s InputPasskeyCredentialClassArray) AsInputPasskeyCredentialFirebasePNV() (to InputPasskeyCredentialFirebasePNVArray) {
	for _, elem := range s {
		value, ok := elem.(*InputPasskeyCredentialFirebasePNV)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// InputPasskeyCredentialPublicKeyArray is adapter for slice of InputPasskeyCredentialPublicKey.
type InputPasskeyCredentialPublicKeyArray []InputPasskeyCredentialPublicKey

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

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

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

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

// InputPasskeyCredentialFirebasePNVArray is adapter for slice of InputPasskeyCredentialFirebasePNV.
type InputPasskeyCredentialFirebasePNVArray []InputPasskeyCredentialFirebasePNV

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

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

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

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