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

// MessageUserVoteClassArray is adapter for slice of MessageUserVoteClass.
type MessageUserVoteClassArray []MessageUserVoteClass

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

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

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

// Last returns last element of slice (if exists).
func (s MessageUserVoteClassArray) Last() (v MessageUserVoteClass, 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 *MessageUserVoteClassArray) PopFirst() (v MessageUserVoteClass, 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 MessageUserVoteClass
	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 *MessageUserVoteClassArray) Pop() (v MessageUserVoteClass, 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 MessageUserVoteClass by Date.
func (s MessageUserVoteClassArray) SortByDate() MessageUserVoteClassArray {
	return s.Sort(func(a, b MessageUserVoteClass) bool {
		return a.GetDate() < b.GetDate()
	})
}

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

// AsMessageUserVote returns copy with only MessageUserVote constructors.
func (s MessageUserVoteClassArray) AsMessageUserVote() (to MessageUserVoteArray) {
	for _, elem := range s {
		value, ok := elem.(*MessageUserVote)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsMessageUserVoteInputOption returns copy with only MessageUserVoteInputOption constructors.
func (s MessageUserVoteClassArray) AsMessageUserVoteInputOption() (to MessageUserVoteInputOptionArray) {
	for _, elem := range s {
		value, ok := elem.(*MessageUserVoteInputOption)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// AsMessageUserVoteMultiple returns copy with only MessageUserVoteMultiple constructors.
func (s MessageUserVoteClassArray) AsMessageUserVoteMultiple() (to MessageUserVoteMultipleArray) {
	for _, elem := range s {
		value, ok := elem.(*MessageUserVoteMultiple)
		if !ok {
			continue
		}
		to = append(to, *value)
	}

	return to
}

// MessageUserVoteArray is adapter for slice of MessageUserVote.
type MessageUserVoteArray []MessageUserVote

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

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

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

// Last returns last element of slice (if exists).
func (s MessageUserVoteArray) Last() (v MessageUserVote, 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 *MessageUserVoteArray) PopFirst() (v MessageUserVote, 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 MessageUserVote
	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 *MessageUserVoteArray) Pop() (v MessageUserVote, 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 MessageUserVote by Date.
func (s MessageUserVoteArray) SortByDate() MessageUserVoteArray {
	return s.Sort(func(a, b MessageUserVote) bool {
		return a.GetDate() < b.GetDate()
	})
}

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

// MessageUserVoteInputOptionArray is adapter for slice of MessageUserVoteInputOption.
type MessageUserVoteInputOptionArray []MessageUserVoteInputOption

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

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

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

// Last returns last element of slice (if exists).
func (s MessageUserVoteInputOptionArray) Last() (v MessageUserVoteInputOption, 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 *MessageUserVoteInputOptionArray) PopFirst() (v MessageUserVoteInputOption, 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 MessageUserVoteInputOption
	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 *MessageUserVoteInputOptionArray) Pop() (v MessageUserVoteInputOption, 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 MessageUserVoteInputOption by Date.
func (s MessageUserVoteInputOptionArray) SortByDate() MessageUserVoteInputOptionArray {
	return s.Sort(func(a, b MessageUserVoteInputOption) bool {
		return a.GetDate() < b.GetDate()
	})
}

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

// MessageUserVoteMultipleArray is adapter for slice of MessageUserVoteMultiple.
type MessageUserVoteMultipleArray []MessageUserVoteMultiple

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

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

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

// Last returns last element of slice (if exists).
func (s MessageUserVoteMultipleArray) Last() (v MessageUserVoteMultiple, 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 *MessageUserVoteMultipleArray) PopFirst() (v MessageUserVoteMultiple, 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 MessageUserVoteMultiple
	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 *MessageUserVoteMultipleArray) Pop() (v MessageUserVoteMultiple, 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 MessageUserVoteMultiple by Date.
func (s MessageUserVoteMultipleArray) SortByDate() MessageUserVoteMultipleArray {
	return s.Sort(func(a, b MessageUserVoteMultiple) bool {
		return a.GetDate() < b.GetDate()
	})
}

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