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

// SecureRequiredTypeClassArray is adapter for slice of SecureRequiredTypeClass.
type SecureRequiredTypeClassArray []SecureRequiredTypeClass

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

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

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

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

// AsSecureRequiredType returns copy with only SecureRequiredType constructors.
func (s SecureRequiredTypeClassArray) AsSecureRequiredType() (to SecureRequiredTypeArray) {
	for _, elem := range s {
		value, ok := elem.(*SecureRequiredType)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsSecureRequiredTypeOneOf returns copy with only SecureRequiredTypeOneOf constructors.
func (s SecureRequiredTypeClassArray) AsSecureRequiredTypeOneOf() (to SecureRequiredTypeOneOfArray) {
	for _, elem := range s {
		value, ok := elem.(*SecureRequiredTypeOneOf)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// SecureRequiredTypeArray is adapter for slice of SecureRequiredType.
type SecureRequiredTypeArray []SecureRequiredType

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

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

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

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

// SecureRequiredTypeOneOfArray is adapter for slice of SecureRequiredTypeOneOf.
type SecureRequiredTypeOneOfArray []SecureRequiredTypeOneOf

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

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

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

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