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

// AccountResetPasswordResultClassArray is adapter for slice of AccountResetPasswordResultClass.
type AccountResetPasswordResultClassArray []AccountResetPasswordResultClass

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

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

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

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

// AsAccountResetPasswordFailedWait returns copy with only AccountResetPasswordFailedWait constructors.
func (s AccountResetPasswordResultClassArray) AsAccountResetPasswordFailedWait() (to AccountResetPasswordFailedWaitArray) {
	for _, elem := range s {
		value, ok := elem.(*AccountResetPasswordFailedWait)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsAccountResetPasswordRequestedWait returns copy with only AccountResetPasswordRequestedWait constructors.
func (s AccountResetPasswordResultClassArray) AsAccountResetPasswordRequestedWait() (to AccountResetPasswordRequestedWaitArray) {
	for _, elem := range s {
		value, ok := elem.(*AccountResetPasswordRequestedWait)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AccountResetPasswordFailedWaitArray is adapter for slice of AccountResetPasswordFailedWait.
type AccountResetPasswordFailedWaitArray []AccountResetPasswordFailedWait

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

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

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

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

// AccountResetPasswordRequestedWaitArray is adapter for slice of AccountResetPasswordRequestedWait.
type AccountResetPasswordRequestedWaitArray []AccountResetPasswordRequestedWait

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

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

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

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