// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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 arrow

import (
	
)

type typeEqualsConfig struct {
	metadata bool
}

// TypeEqualOption is a functional option type used for configuring type
// equality checks.
type TypeEqualOption func(*typeEqualsConfig)

// CheckMetadata is an option for TypeEqual that allows checking for metadata
// equality besides type equality. It only makes sense for types with metadata.
func () TypeEqualOption {
	return func( *typeEqualsConfig) {
		.metadata = true
	}
}

// TypeEqual checks if two DataType are the same, optionally checking metadata
// equality for STRUCT types.
func (,  DataType,  ...TypeEqualOption) bool {
	var  typeEqualsConfig
	for ,  := range  {
		(&)
	}

	switch {
	case  == nil ||  == nil:
		return  == nil &&  == nil
	case .ID() != .ID():
		return false
	}

	switch l := .(type) {
	case ExtensionType:
		return .ExtensionEquals(.(ExtensionType))
	case *ListType:
		if !(.Elem(), .(*ListType).Elem(), ...) {
			return false
		}
		if .metadata && !.elem.Metadata.Equal(.(*ListType).elem.Metadata) {
			return false
		}
		return .elem.Nullable == .(*ListType).elem.Nullable
	case *FixedSizeListType:
		if !(.Elem(), .(*FixedSizeListType).Elem(), ...) {
			return false
		}
		if .metadata && !.elem.Metadata.Equal(.(*FixedSizeListType).elem.Metadata) {
			return false
		}
		return .n == .(*FixedSizeListType).n && .elem.Nullable == .(*FixedSizeListType).elem.Nullable
	case *MapType:
		if !(.KeyType(), .(*MapType).KeyType(), ...) {
			return false
		}
		if !(.ItemType(), .(*MapType).ItemType(), ...) {
			return false
		}
		if .KeyField().Nullable != .(*MapType).KeyField().Nullable {
			return false
		}
		if .ItemField().Nullable != .(*MapType).ItemField().Nullable {
			return false
		}
		if .metadata {
			if !.KeyField().Metadata.Equal(.(*MapType).KeyField().Metadata) {
				return false
			}
			if !.ItemField().Metadata.Equal(.(*MapType).ItemField().Metadata) {
				return false
			}
		}
		return true
	case *StructType:
		 := .(*StructType)
		switch {
		case len(.fields) != len(.fields):
			return false
		case !reflect.DeepEqual(.index, .index):
			return false
		}
		for  := range .fields {
			,  := .fields[], .fields[]
			switch {
			case .Name != .Name:
				return false
			case .Nullable != .Nullable:
				return false
			case !(.Type, .Type, ...):
				return false
			case .metadata && !.Metadata.Equal(.Metadata):
				return false
			}
		}
		return true
	case UnionType:
		 := .(UnionType)
		if .Mode() != .Mode() {
			return false
		}

		if !reflect.DeepEqual(.ChildIDs(), .ChildIDs()) {
			return false
		}

		for  := range .Fields() {
			,  := .Fields()[], .Fields()[]
			switch {
			case .Name != .Name:
				return false
			case .Nullable != .Nullable:
				return false
			case !(.Type, .Type, ...):
				return false
			case .metadata && !.Metadata.Equal(.Metadata):
				return false
			case .TypeCodes()[] != .TypeCodes()[]:
				return false
			}
		}
		return true
	case *TimestampType:
		 := .(*TimestampType)
		return .Unit == .Unit && .TimeZone == .TimeZone
	case *RunEndEncodedType:
		 := .(*RunEndEncodedType)
		return (.Encoded(), .Encoded(), ...) &&
			(.runEnds, .runEnds, ...)
	default:
		return reflect.DeepEqual(, )
	}
}