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

// InputAiComposeToneClassArray is adapter for slice of InputAiComposeToneClass.
type InputAiComposeToneClassArray []InputAiComposeToneClass

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

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

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

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

// AsInputAiComposeToneDefault returns copy with only InputAiComposeToneDefault constructors.
func (s InputAiComposeToneClassArray) AsInputAiComposeToneDefault() (to InputAiComposeToneDefaultArray) {
	for _, elem := range s {
		value, ok := elem.(*InputAiComposeToneDefault)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsInputAiComposeToneID returns copy with only InputAiComposeToneID constructors.
func (s InputAiComposeToneClassArray) AsInputAiComposeToneID() (to InputAiComposeToneIDArray) {
	for _, elem := range s {
		value, ok := elem.(*InputAiComposeToneID)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsInputAiComposeToneSlug returns copy with only InputAiComposeToneSlug constructors.
func (s InputAiComposeToneClassArray) AsInputAiComposeToneSlug() (to InputAiComposeToneSlugArray) {
	for _, elem := range s {
		value, ok := elem.(*InputAiComposeToneSlug)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// InputAiComposeToneDefaultArray is adapter for slice of InputAiComposeToneDefault.
type InputAiComposeToneDefaultArray []InputAiComposeToneDefault

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

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

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

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

// InputAiComposeToneIDArray is adapter for slice of InputAiComposeToneID.
type InputAiComposeToneIDArray []InputAiComposeToneID

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

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

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

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

// SortByID sorts slice of InputAiComposeToneID by ID.
func (s InputAiComposeToneIDArray) SortByID() InputAiComposeToneIDArray {
	return s.Sort(func(a, b InputAiComposeToneID) bool {
		return a.GetID() < b.GetID()
	})
}

// SortStableByID sorts slice of InputAiComposeToneID by ID.
func (s InputAiComposeToneIDArray) SortStableByID() InputAiComposeToneIDArray {
	return s.SortStable(func(a, b InputAiComposeToneID) bool {
		return a.GetID() < b.GetID()
	})
}

// FillMap fills constructors to given map.
func (s InputAiComposeToneIDArray) FillMap(to map[int64]InputAiComposeToneID) {
	for _, value := range s {
		to[value.GetID()] = value
	}
}

// ToMap collects constructors to map.
func (s InputAiComposeToneIDArray) ToMap() map[int64]InputAiComposeToneID {
	r := make(map[int64]InputAiComposeToneID, len(s))
	s.FillMap(r)
	return r
}

// InputAiComposeToneSlugArray is adapter for slice of InputAiComposeToneSlug.
type InputAiComposeToneSlugArray []InputAiComposeToneSlug

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

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

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

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