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

// InputStorePaymentPurposeClassArray is adapter for slice of InputStorePaymentPurposeClass.
type InputStorePaymentPurposeClassArray []InputStorePaymentPurposeClass

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

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

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

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

// AsInputStorePaymentPremiumSubscription returns copy with only InputStorePaymentPremiumSubscription constructors.
func (s InputStorePaymentPurposeClassArray) AsInputStorePaymentPremiumSubscription() (to InputStorePaymentPremiumSubscriptionArray) {
	for _, elem := range s {
		value, ok := elem.(*InputStorePaymentPremiumSubscription)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsInputStorePaymentGiftPremium returns copy with only InputStorePaymentGiftPremium constructors.
func (s InputStorePaymentPurposeClassArray) AsInputStorePaymentGiftPremium() (to InputStorePaymentGiftPremiumArray) {
	for _, elem := range s {
		value, ok := elem.(*InputStorePaymentGiftPremium)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// InputStorePaymentPremiumSubscriptionArray is adapter for slice of InputStorePaymentPremiumSubscription.
type InputStorePaymentPremiumSubscriptionArray []InputStorePaymentPremiumSubscription

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

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

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

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

// InputStorePaymentGiftPremiumArray is adapter for slice of InputStorePaymentGiftPremium.
type InputStorePaymentGiftPremiumArray []InputStorePaymentGiftPremium

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

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

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

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