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

// StarGiftAttributeIDClassArray is adapter for slice of StarGiftAttributeIDClass.
type StarGiftAttributeIDClassArray []StarGiftAttributeIDClass

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

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

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

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

// AsStarGiftAttributeIDModel returns copy with only StarGiftAttributeIDModel constructors.
func (s StarGiftAttributeIDClassArray) AsStarGiftAttributeIDModel() (to StarGiftAttributeIDModelArray) {
	for _, elem := range s {
		value, ok := elem.(*StarGiftAttributeIDModel)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsStarGiftAttributeIDPattern returns copy with only StarGiftAttributeIDPattern constructors.
func (s StarGiftAttributeIDClassArray) AsStarGiftAttributeIDPattern() (to StarGiftAttributeIDPatternArray) {
	for _, elem := range s {
		value, ok := elem.(*StarGiftAttributeIDPattern)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsStarGiftAttributeIDBackdrop returns copy with only StarGiftAttributeIDBackdrop constructors.
func (s StarGiftAttributeIDClassArray) AsStarGiftAttributeIDBackdrop() (to StarGiftAttributeIDBackdropArray) {
	for _, elem := range s {
		value, ok := elem.(*StarGiftAttributeIDBackdrop)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// StarGiftAttributeIDModelArray is adapter for slice of StarGiftAttributeIDModel.
type StarGiftAttributeIDModelArray []StarGiftAttributeIDModel

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

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

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

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

// StarGiftAttributeIDPatternArray is adapter for slice of StarGiftAttributeIDPattern.
type StarGiftAttributeIDPatternArray []StarGiftAttributeIDPattern

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

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

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

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

// StarGiftAttributeIDBackdropArray is adapter for slice of StarGiftAttributeIDBackdrop.
type StarGiftAttributeIDBackdropArray []StarGiftAttributeIDBackdrop

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

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

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

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