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

// InputStarGiftAuctionClassArray is adapter for slice of InputStarGiftAuctionClass.
type InputStarGiftAuctionClassArray []InputStarGiftAuctionClass

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

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

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

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

// AsInputStarGiftAuction returns copy with only InputStarGiftAuction constructors.
func (s InputStarGiftAuctionClassArray) AsInputStarGiftAuction() (to InputStarGiftAuctionArray) {
	for _, elem := range s {
		value, ok := elem.(*InputStarGiftAuction)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsInputStarGiftAuctionSlug returns copy with only InputStarGiftAuctionSlug constructors.
func (s InputStarGiftAuctionClassArray) AsInputStarGiftAuctionSlug() (to InputStarGiftAuctionSlugArray) {
	for _, elem := range s {
		value, ok := elem.(*InputStarGiftAuctionSlug)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// InputStarGiftAuctionArray is adapter for slice of InputStarGiftAuction.
type InputStarGiftAuctionArray []InputStarGiftAuction

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

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

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

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

// InputStarGiftAuctionSlugArray is adapter for slice of InputStarGiftAuctionSlug.
type InputStarGiftAuctionSlugArray []InputStarGiftAuctionSlug

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

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

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

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