/*
 * @FileName:   if.go
 * @Author:		JJXu
 * @CreateTime:	2022/3/31 下午10:34
 * @Description:
 */

package utils

import "strings"

func If(condition bool, trueVal, falseVal interface{}) interface{} {
	if condition {
		return trueVal
	}
	return falseVal
}
func IfGec[T ~string | ~int | ~int32 | ~int64 | ~bool | ~float32 | ~float64](condition bool, trueVal, falseVal T) T {
	if condition {
		return trueVal
	}
	return falseVal
}

// IsValueInList 值是否在列表中
// value:查询的值
// list: 列表
// disableStrictCase: 禁用严格大小写检查。默认是严格大小写
func IsValueInList(value string, list []string, disableStrictCase ...bool) bool {
	var disStrictCase bool
	if disableStrictCase != nil {
		disStrictCase = disableStrictCase[0]
	}
	for _, v := range list {
		var listValue string
		if disStrictCase {
			listValue = strings.ToLower(v)
			value = strings.ToLower(v)
		} else {
			listValue = v
		}
		if listValue == value {
			return true
		}
	}
	return false
}
