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

// ReactionClassArray is adapter for slice of ReactionClass.
type ReactionClassArray []ReactionClass

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

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

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

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

// AsReactionEmoji returns copy with only ReactionEmoji constructors.
func (s ReactionClassArray) AsReactionEmoji() (to ReactionEmojiArray) {
	for _, elem := range s {
		value, ok := elem.(*ReactionEmoji)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsReactionCustomEmoji returns copy with only ReactionCustomEmoji constructors.
func (s ReactionClassArray) AsReactionCustomEmoji() (to ReactionCustomEmojiArray) {
	for _, elem := range s {
		value, ok := elem.(*ReactionCustomEmoji)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// ReactionEmojiArray is adapter for slice of ReactionEmoji.
type ReactionEmojiArray []ReactionEmoji

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

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

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

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

// ReactionCustomEmojiArray is adapter for slice of ReactionCustomEmoji.
type ReactionCustomEmojiArray []ReactionCustomEmoji

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

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

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

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