package pgtype

import (
	
	
	
	
	
)

const maxUint = ^uint(0)
const maxInt = int(maxUint >> 1)
const minInt = -maxInt - 1
underlyingNumberType gets the underlying type that can be converted to Int2, Int4, Int8, Float4, or Float8
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	case reflect.Int:
		 := int(.Int())
		return , reflect.TypeOf() != .Type()
	case reflect.Int8:
		 := int8(.Int())
		return , reflect.TypeOf() != .Type()
	case reflect.Int16:
		 := int16(.Int())
		return , reflect.TypeOf() != .Type()
	case reflect.Int32:
		 := int32(.Int())
		return , reflect.TypeOf() != .Type()
	case reflect.Int64:
		 := int64(.Int())
		return , reflect.TypeOf() != .Type()
	case reflect.Uint:
		 := uint(.Uint())
		return , reflect.TypeOf() != .Type()
	case reflect.Uint8:
		 := uint8(.Uint())
		return , reflect.TypeOf() != .Type()
	case reflect.Uint16:
		 := uint16(.Uint())
		return , reflect.TypeOf() != .Type()
	case reflect.Uint32:
		 := uint32(.Uint())
		return , reflect.TypeOf() != .Type()
	case reflect.Uint64:
		 := uint64(.Uint())
		return , reflect.TypeOf() != .Type()
	case reflect.Float32:
		 := float32(.Float())
		return , reflect.TypeOf() != .Type()
	case reflect.Float64:
		 := .Float()
		return , reflect.TypeOf() != .Type()
	case reflect.String:
		 := .String()
		return , reflect.TypeOf() != .Type()
	}

	return nil, false
}
underlyingBoolType gets the underlying type that can be converted to Bool
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	case reflect.Bool:
		 := .Bool()
		return , reflect.TypeOf() != .Type()
	}

	return nil, false
}
underlyingBytesType gets the underlying type that can be converted to []byte
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	case reflect.Slice:
		if .Type().Elem().Kind() == reflect.Uint8 {
			 := .Bytes()
			return , reflect.TypeOf() != .Type()
		}
	}

	return nil, false
}
underlyingStringType gets the underlying type that can be converted to String
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	case reflect.String:
		 := .String()
		return , reflect.TypeOf() != .Type()
	}

	return nil, false
}
underlyingPtrType dereferences a pointer
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	}

	return nil, false
}
underlyingTimeType gets the underlying type that can be converted to time.Time
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	}

	 := reflect.TypeOf(time.Time{})
	if .Type().ConvertibleTo() {
		return .Convert().Interface(), true
	}

	return nil, false
}
underlyingUUIDType gets the underlying type that can be converted to [16]byte
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return time.Time{}, false
		}
		 := .Elem().Interface()
		return , true
	}

	 := reflect.TypeOf([16]byte{})
	if .Type().ConvertibleTo() {
		return .Convert().Interface(), true
	}

	return nil, false
}
underlyingSliceType gets the underlying slice type
func ( interface{}) (interface{}, bool) {
	 := reflect.ValueOf()

	switch .Kind() {
	case reflect.Ptr:
		if .IsNil() {
			return nil, false
		}
		 := .Elem().Interface()
		return , true
	case reflect.Slice:
		 := reflect.SliceOf(.Type().Elem())
		if .Type().ConvertibleTo() {
			 := .Convert()
			return .Interface(), reflect.TypeOf(.Interface()) != .Type()
		}
	}

	return nil, false
}

func ( int64,  Status,  interface{}) error {
	if  == Present {
		switch v := .(type) {
		case *int:
			if  < int64(minInt) {
				return fmt.Errorf("%d is less than minimum value for int", )
			} else if  > int64(maxInt) {
				return fmt.Errorf("%d is greater than maximum value for int", )
			}
			* = int()
		case *int8:
			if  < math.MinInt8 {
				return fmt.Errorf("%d is less than minimum value for int8", )
			} else if  > math.MaxInt8 {
				return fmt.Errorf("%d is greater than maximum value for int8", )
			}
			* = int8()
		case *int16:
			if  < math.MinInt16 {
				return fmt.Errorf("%d is less than minimum value for int16", )
			} else if  > math.MaxInt16 {
				return fmt.Errorf("%d is greater than maximum value for int16", )
			}
			* = int16()
		case *int32:
			if  < math.MinInt32 {
				return fmt.Errorf("%d is less than minimum value for int32", )
			} else if  > math.MaxInt32 {
				return fmt.Errorf("%d is greater than maximum value for int32", )
			}
			* = int32()
		case *int64:
			if  < math.MinInt64 {
				return fmt.Errorf("%d is less than minimum value for int64", )
			} else if  > math.MaxInt64 {
				return fmt.Errorf("%d is greater than maximum value for int64", )
			}
			* = int64()
		case *uint:
			if  < 0 {
				return fmt.Errorf("%d is less than zero for uint", )
			} else if uint64() > uint64(maxUint) {
				return fmt.Errorf("%d is greater than maximum value for uint", )
			}
			* = uint()
		case *uint8:
			if  < 0 {
				return fmt.Errorf("%d is less than zero for uint8", )
			} else if  > math.MaxUint8 {
				return fmt.Errorf("%d is greater than maximum value for uint8", )
			}
			* = uint8()
		case *uint16:
			if  < 0 {
				return fmt.Errorf("%d is less than zero for uint32", )
			} else if  > math.MaxUint16 {
				return fmt.Errorf("%d is greater than maximum value for uint16", )
			}
			* = uint16()
		case *uint32:
			if  < 0 {
				return fmt.Errorf("%d is less than zero for uint32", )
			} else if  > math.MaxUint32 {
				return fmt.Errorf("%d is greater than maximum value for uint32", )
			}
			* = uint32()
		case *uint64:
			if  < 0 {
				return fmt.Errorf("%d is less than zero for uint64", )
			}
			* = uint64()
		case sql.Scanner:
			return .Scan()
		default:
			if  := reflect.ValueOf(); .Kind() == reflect.Ptr {
				 := .Elem()
if dst is a pointer to pointer, strip the pointer and try again
				case reflect.Ptr:
allocate destination
						.Set(reflect.New(.Type().Elem()))
					}
					return (, , .Interface())
				case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
					if .OverflowInt(int64()) {
						return fmt.Errorf("cannot put %d into %T", , )
					}
					.SetInt(int64())
					return nil
				case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
					if  < 0 {
						return fmt.Errorf("%d is less than zero for %T", , )
					}
					if .OverflowUint(uint64()) {
						return fmt.Errorf("cannot put %d into %T", , )
					}
					.SetUint(uint64())
					return nil
				}
			}
			return fmt.Errorf("cannot assign %v into %T", , )
		}
		return nil
	}
if dst is a pointer to pointer and srcStatus is not Present, nil it out
	if  := reflect.ValueOf(); .Kind() == reflect.Ptr {
		 := .Elem()
		if .Kind() == reflect.Ptr {
			.Set(reflect.Zero(.Type()))
			return nil
		}
	}

	return fmt.Errorf("cannot assign %v %v into %T", , , )
}

func ( float64,  Status,  interface{}) error {
	if  == Present {
		switch v := .(type) {
		case *float32:
			* = float32()
		case *float64:
			* = 
		default:
			if  := reflect.ValueOf(); .Kind() == reflect.Ptr {
				 := .Elem()
if dst is a pointer to pointer, strip the pointer and try again
				case reflect.Ptr:
allocate destination
						.Set(reflect.New(.Type().Elem()))
					}
					return (, , .Interface())
				case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
					 := int64()
					if float64() ==  {
						return int64AssignTo(, , )
					}
				}
			}
			return fmt.Errorf("cannot assign %v into %T", , )
		}
		return nil
	}
if dst is a pointer to pointer and srcStatus is not Present, nil it out
	if  := reflect.ValueOf(); .Kind() == reflect.Ptr {
		 := .Elem()
		if .Kind() == reflect.Ptr {
			.Set(reflect.Zero(.Type()))
			return nil
		}
	}

	return fmt.Errorf("cannot assign %v %v into %T", , , )
}

func ( interface{}) 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
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 ( interface{}) (interface{}, 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()];  {
		 := .Convert(reflect.PtrTo())
		return .Interface(), .Type() != .Type()
	}

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

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

	return nil, false
}

func () {
	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(""),
	}