// 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 extensions

import (
	
	
	
	

	
	
)

// OpaqueType is a placeholder for a type from an external (usually
// non-Arrow) system that could not be interpreted.
type OpaqueType struct {
	arrow.ExtensionBase `json:"-"`

	TypeName   string `json:"type_name"`
	VendorName string `json:"vendor_name"`
}

// NewOpaqueType creates a new OpaqueType with the provided storage type, type name, and vendor name.
func ( arrow.DataType, ,  string) *OpaqueType {
	return &OpaqueType{ExtensionBase: arrow.ExtensionBase{Storage: },
		TypeName: , VendorName: }
}

func (*OpaqueType) () reflect.Type {
	return reflect.TypeOf(OpaqueArray{})
}

func (*OpaqueType) () string {
	return "arrow.opaque"
}

func ( *OpaqueType) () string {
	return fmt.Sprintf("extension<%s[storage_type=%s, type_name=%s, vendor_name=%s]>",
		.ExtensionName(), .Storage, .TypeName, .VendorName)
}

func ( *OpaqueType) () string {
	,  := json.Marshal()
	return string()
}

func (*OpaqueType) ( arrow.DataType,  string) (arrow.ExtensionType, error) {
	var  OpaqueType
	 := json.Unmarshal(unsafe.Slice(unsafe.StringData(), len()), &)
	if  != nil {
		return nil, 
	}

	switch {
	case .TypeName == "":
		return nil, fmt.Errorf("%w: serialized JSON data for OpaqueType missing type_name",
			arrow.ErrInvalid)
	case .VendorName == "":
		return nil, fmt.Errorf("%w: serialized JSON data for OpaqueType missing vendor_name",
			arrow.ErrInvalid)
	}

	.ExtensionBase = arrow.ExtensionBase{Storage: }
	return &, nil
}

func ( *OpaqueType) ( arrow.ExtensionType) bool {
	if .ExtensionName() != .ExtensionName() {
		return false
	}

	,  := .(*OpaqueType)
	if ! {
		return false
	}

	return arrow.TypeEqual(.Storage, .Storage) &&
		.TypeName == .TypeName &&
		.VendorName == .VendorName
}

// OpaqueArray is a placeholder for data from an external (usually
// non-Arrow) system that could not be interpreted.
type OpaqueArray struct {
	array.ExtensionArrayBase
}

var (
	_ arrow.ExtensionType  = (*OpaqueType)(nil)
	_ array.ExtensionArray = (*OpaqueArray)(nil)
)