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

// BroadcastRevenueTransactionClassArray is adapter for slice of BroadcastRevenueTransactionClass.
type BroadcastRevenueTransactionClassArray []BroadcastRevenueTransactionClass

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

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

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

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

// AsBroadcastRevenueTransactionProceeds returns copy with only BroadcastRevenueTransactionProceeds constructors.
func (s BroadcastRevenueTransactionClassArray) AsBroadcastRevenueTransactionProceeds() (to BroadcastRevenueTransactionProceedsArray) {
	for _, elem := range s {
		value, ok := elem.(*BroadcastRevenueTransactionProceeds)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsBroadcastRevenueTransactionWithdrawal returns copy with only BroadcastRevenueTransactionWithdrawal constructors.
func (s BroadcastRevenueTransactionClassArray) AsBroadcastRevenueTransactionWithdrawal() (to BroadcastRevenueTransactionWithdrawalArray) {
	for _, elem := range s {
		value, ok := elem.(*BroadcastRevenueTransactionWithdrawal)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsBroadcastRevenueTransactionRefund returns copy with only BroadcastRevenueTransactionRefund constructors.
func (s BroadcastRevenueTransactionClassArray) AsBroadcastRevenueTransactionRefund() (to BroadcastRevenueTransactionRefundArray) {
	for _, elem := range s {
		value, ok := elem.(*BroadcastRevenueTransactionRefund)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// BroadcastRevenueTransactionProceedsArray is adapter for slice of BroadcastRevenueTransactionProceeds.
type BroadcastRevenueTransactionProceedsArray []BroadcastRevenueTransactionProceeds

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

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

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

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

// BroadcastRevenueTransactionWithdrawalArray is adapter for slice of BroadcastRevenueTransactionWithdrawal.
type BroadcastRevenueTransactionWithdrawalArray []BroadcastRevenueTransactionWithdrawal

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

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

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

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

// SortByDate sorts slice of BroadcastRevenueTransactionWithdrawal by Date.
func (s BroadcastRevenueTransactionWithdrawalArray) SortByDate() BroadcastRevenueTransactionWithdrawalArray {
	return s.Sort(func(a, b BroadcastRevenueTransactionWithdrawal) bool {
		return a.GetDate() < b.GetDate()
	})
}

// SortStableByDate sorts slice of BroadcastRevenueTransactionWithdrawal by Date.
func (s BroadcastRevenueTransactionWithdrawalArray) SortStableByDate() BroadcastRevenueTransactionWithdrawalArray {
	return s.SortStable(func(a, b BroadcastRevenueTransactionWithdrawal) bool {
		return a.GetDate() < b.GetDate()
	})
}

// BroadcastRevenueTransactionRefundArray is adapter for slice of BroadcastRevenueTransactionRefund.
type BroadcastRevenueTransactionRefundArray []BroadcastRevenueTransactionRefund

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

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

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

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

// SortByDate sorts slice of BroadcastRevenueTransactionRefund by Date.
func (s BroadcastRevenueTransactionRefundArray) SortByDate() BroadcastRevenueTransactionRefundArray {
	return s.Sort(func(a, b BroadcastRevenueTransactionRefund) bool {
		return a.GetDate() < b.GetDate()
	})
}

// SortStableByDate sorts slice of BroadcastRevenueTransactionRefund by Date.
func (s BroadcastRevenueTransactionRefundArray) SortStableByDate() BroadcastRevenueTransactionRefundArray {
	return s.SortStable(func(a, b BroadcastRevenueTransactionRefund) bool {
		return a.GetDate() < b.GetDate()
	})
}
