// Copyright 2025 The Bucketeer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package util

import "sort"

// Int64Slice attaches the methods of sort.Interface to []int64, sorting in increasing order.
type Int64Slice []int64

func (p Int64Slice) Len() int {
	return len(p)
}

func (p Int64Slice) Less(i, j int) bool {
	return p[i] < p[j]
}

func (p Int64Slice) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func Int64sAreSorted(a []int64) bool {
	return sort.IsSorted(Int64Slice(a))
}

func Int64sAreReverseSorted(a []int64) bool {
	return sort.IsSorted(sort.Reverse(Int64Slice(a)))
}

// Int32Slice attaches the methods of sort.Interface to []int32, sorting in increasing order.
type Int32Slice []int32

func (p Int32Slice) Len() int {
	return len(p)
}

func (p Int32Slice) Less(i, j int) bool {
	return p[i] < p[j]
}

func (p Int32Slice) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func Int32sAreSorted(a []int32) bool {
	return sort.IsSorted(Int32Slice(a))
}

func Int32sAreReverseSorted(a []int32) bool {
	return sort.IsSorted(sort.Reverse(Int32Slice(a)))
}

func StringsAreReverseSorted(a []string) bool {
	return sort.IsSorted(sort.Reverse(sort.StringSlice(a)))
}
