// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.

package kern

import "reflect"

func Equal(value1, value2 any) (equal bool) {
	if value1 == nil && value2 == nil {
		equal = true
	} else if value1 == nil || value2 == nil {
		equal = false
	} else if IsBool(value1) && IsBool(value2) {
		equal = value1.(bool) == value2.(bool)
	} else if IsList(value1) && IsList(value2) {
		ls1 := value1.(*ListType)
		ls2 := value2.(*ListType)
		equal = ls1.Equals(*ls2)
	} else if IsDict(value1) && IsDict(value2) {
		d1 := value1.(*DictType)
		d2 := value2.(*DictType)
		equal = d1.Equals(*d2)
	} else if IsInteger(value1) && IsInteger(value2) {
		equal = value1.(int64) == value2.(int64)
	} else if IsString(value1) && IsString(value2) {
		equal = value1.(string) == value2.(string)
	} else if IsFloat(value1) && IsFloat(value2) {
		equal = value1.(float64) == value2.(float64)
	} else if IsNumOrFract(value1) && IsNumOrFract(value2) {
		if eq, err := CmpAnyFract(value1, value2); err == nil {
			equal = eq == 0
		}
	} else if !reflect.DeepEqual(value1, value2) {
		equal = false
	}
	return
}
