package pgtype

import (
	
)

func ( any) error {
	 := reflect.ValueOf()

	// AssignTo dst must always be a pointer
	if .Kind() != reflect.Ptr {
		return &nullAssignmentError{dst: }
	}

	 := .Elem()

	switch .Kind() {
	case reflect.Ptr, reflect.Slice, reflect.Map:
		.Set(reflect.Zero(.Type()))
		return nil
	}

	return &nullAssignmentError{dst: }
}

var kindTypes map[reflect.Kind]reflect.Type

func toInterface( reflect.Value,  reflect.Type) (any, bool) {
	 := .Convert()
	return .Interface(), .Type() != .Type()
}

// GetAssignToDstType attempts to convert dst to something AssignTo can assign
// to. If dst is a pointer to pointer it allocates a value and returns the
// dereferences pointer. If dst is a named type such as *Foo where Foo is type
// Foo int16, it converts dst to *int16.
//
// GetAssignToDstType returns the converted dst and a bool representing if any
// change was made.
func ( any) (any, bool) {
	 := reflect.ValueOf()

	// AssignTo dst must always be a pointer
	if .Kind() != reflect.Ptr {
		return nil, false
	}

	 := .Elem()

	// if dst is a pointer to pointer, allocate space try again with the dereferenced pointer
	if .Kind() == reflect.Ptr {
		.Set(reflect.New(.Type().Elem()))
		return .Interface(), true
	}

	// if dst is pointer to a base type that has been renamed
	if ,  := kindTypes[.Kind()];  {
		return toInterface(, reflect.PtrTo())
	}

	if .Kind() == reflect.Slice {
		if ,  := kindTypes[.Type().Elem().Kind()];  {
			return toInterface(, reflect.PtrTo(reflect.SliceOf()))
		}
	}

	if .Kind() == reflect.Array {
		if ,  := kindTypes[.Type().Elem().Kind()];  {
			return toInterface(, reflect.PtrTo(reflect.ArrayOf(.Len(), )))
		}
	}

	if .Kind() == reflect.Struct {
		if .Type().NumField() == 1 && .Type().Field(0).Anonymous {
			 = .Field(0).Addr()
			 := .Type().Field(0).Type
			if .Kind() == reflect.Array {
				if ,  := kindTypes[.Elem().Kind()];  {
					return toInterface(, reflect.PtrTo(reflect.ArrayOf(.Len(), )))
				}
			}
			if ,  := kindTypes[.Kind()];  && .CanInterface() {
				return .Interface(), true
			}
		}
	}

	return nil, false
}

func init() {
	kindTypes = map[reflect.Kind]reflect.Type{
		reflect.Bool:    reflect.TypeOf(false),
		reflect.Float32: reflect.TypeOf(float32(0)),
		reflect.Float64: reflect.TypeOf(float64(0)),
		reflect.Int:     reflect.TypeOf(int(0)),
		reflect.Int8:    reflect.TypeOf(int8(0)),
		reflect.Int16:   reflect.TypeOf(int16(0)),
		reflect.Int32:   reflect.TypeOf(int32(0)),
		reflect.Int64:   reflect.TypeOf(int64(0)),
		reflect.Uint:    reflect.TypeOf(uint(0)),
		reflect.Uint8:   reflect.TypeOf(uint8(0)),
		reflect.Uint16:  reflect.TypeOf(uint16(0)),
		reflect.Uint32:  reflect.TypeOf(uint32(0)),
		reflect.Uint64:  reflect.TypeOf(uint64(0)),
		reflect.String:  reflect.TypeOf(""),
	}
}