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

// MessagesEmojiGameInfoClassArray is adapter for slice of MessagesEmojiGameInfoClass.
type MessagesEmojiGameInfoClassArray []MessagesEmojiGameInfoClass

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

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

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

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

// AsMessagesEmojiGameDiceInfo returns copy with only MessagesEmojiGameDiceInfo constructors.
func (s MessagesEmojiGameInfoClassArray) AsMessagesEmojiGameDiceInfo() (to MessagesEmojiGameDiceInfoArray) {
	for _, elem := range s {
		value, ok := elem.(*MessagesEmojiGameDiceInfo)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AppendOnlyAvailable appends only Available constructors to
// given slice.
func (s MessagesEmojiGameInfoClassArray) AppendOnlyAvailable(to []*MessagesEmojiGameDiceInfo) []*MessagesEmojiGameDiceInfo {
	for _, elem := range s {
		value, ok := elem.AsAvailable()
		if !ok {
			continue
		}
		to = append(to, value)
	}

	return to
}

// AsAvailable returns copy with only Available constructors.
func (s MessagesEmojiGameInfoClassArray) AsAvailable() (to []*MessagesEmojiGameDiceInfo) {
	return s.AppendOnlyAvailable(to)
}

// FirstAsAvailable returns first element of slice (if exists).
func (s MessagesEmojiGameInfoClassArray) FirstAsAvailable() (v *MessagesEmojiGameDiceInfo, ok bool) {
	value, ok := s.First()
	if !ok {
		return
	}
	return value.AsAvailable()
}

// LastAsAvailable returns last element of slice (if exists).
func (s MessagesEmojiGameInfoClassArray) LastAsAvailable() (v *MessagesEmojiGameDiceInfo, ok bool) {
	value, ok := s.Last()
	if !ok {
		return
	}
	return value.AsAvailable()
}

// PopFirstAsAvailable returns element of slice (if exists).
func (s *MessagesEmojiGameInfoClassArray) PopFirstAsAvailable() (v *MessagesEmojiGameDiceInfo, ok bool) {
	value, ok := s.PopFirst()
	if !ok {
		return
	}
	return value.AsAvailable()
}

// PopAsAvailable returns element of slice (if exists).
func (s *MessagesEmojiGameInfoClassArray) PopAsAvailable() (v *MessagesEmojiGameDiceInfo, ok bool) {
	value, ok := s.Pop()
	if !ok {
		return
	}
	return value.AsAvailable()
}

// MessagesEmojiGameDiceInfoArray is adapter for slice of MessagesEmojiGameDiceInfo.
type MessagesEmojiGameDiceInfoArray []MessagesEmojiGameDiceInfo

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

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

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

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