package pgtype

import (
	
	

	
)

type Int4range struct {
	Lower     Int4
	Upper     Int4
	LowerType BoundType
	UpperType BoundType
	Status    Status
}

untyped nil and typed nil interfaces are different
	if  == nil {
		* = Int4range{Status: Null}
		return nil
	}

	switch value := .(type) {
	case Int4range:
		* = 
	case *Int4range:
		* = *
	case string:
		return .DecodeText(nil, []byte())
	default:
		return fmt.Errorf("cannot convert %v to Int4range", )
	}

	return nil
}

func ( Int4range) () interface{} {
	switch .Status {
	case Present:
		return 
	case Null:
		return nil
	default:
		return .Status
	}
}

func ( *Int4range) ( interface{}) error {
	return fmt.Errorf("cannot assign %v to %T", , )
}

func ( *Int4range) ( *ConnInfo,  []byte) error {
	if  == nil {
		* = Int4range{Status: Null}
		return nil
	}

	,  := ParseUntypedTextRange(string())
	if  != nil {
		return 
	}

	* = Int4range{Status: Present}

	.LowerType = .LowerType
	.UpperType = .UpperType

	if .LowerType == Empty {
		return nil
	}

	if .LowerType == Inclusive || .LowerType == Exclusive {
		if  := .Lower.DecodeText(, []byte(.Lower));  != nil {
			return 
		}
	}

	if .UpperType == Inclusive || .UpperType == Exclusive {
		if  := .Upper.DecodeText(, []byte(.Upper));  != nil {
			return 
		}
	}

	return nil
}

func ( *Int4range) ( *ConnInfo,  []byte) error {
	if  == nil {
		* = Int4range{Status: Null}
		return nil
	}

	,  := ParseUntypedBinaryRange()
	if  != nil {
		return 
	}

	* = Int4range{Status: Present}

	.LowerType = .LowerType
	.UpperType = .UpperType

	if .LowerType == Empty {
		return nil
	}

	if .LowerType == Inclusive || .LowerType == Exclusive {
		if  := .Lower.DecodeBinary(, .Lower);  != nil {
			return 
		}
	}

	if .UpperType == Inclusive || .UpperType == Exclusive {
		if  := .Upper.DecodeBinary(, .Upper);  != nil {
			return 
		}
	}

	return nil
}

func ( Int4range) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .Status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	switch .LowerType {
	case Exclusive, Unbounded:
		 = append(, '(')
	case Inclusive:
		 = append(, '[')
	case Empty:
		return append(, "empty"...), nil
	default:
		return nil, fmt.Errorf("unknown lower bound type %v", .LowerType)
	}

	var  error

	if .LowerType != Unbounded {
		,  = .Lower.EncodeText(, )
		if  != nil {
			return nil, 
		} else if  == nil {
			return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded")
		}
	}

	 = append(, ',')

	if .UpperType != Unbounded {
		,  = .Upper.EncodeText(, )
		if  != nil {
			return nil, 
		} else if  == nil {
			return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded")
		}
	}

	switch .UpperType {
	case Exclusive, Unbounded:
		 = append(, ')')
	case Inclusive:
		 = append(, ']')
	default:
		return nil, fmt.Errorf("unknown upper bound type %v", .UpperType)
	}

	return , nil
}

func ( Int4range) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .Status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	var  byte
	switch .LowerType {
	case Inclusive:
		 |= lowerInclusiveMask
	case Unbounded:
		 |= lowerUnboundedMask
	case Exclusive:
	case Empty:
		return append(, emptyMask), nil
	default:
		return nil, fmt.Errorf("unknown LowerType: %v", .LowerType)
	}

	switch .UpperType {
	case Inclusive:
		 |= upperInclusiveMask
	case Unbounded:
		 |= upperUnboundedMask
	case Exclusive:
	default:
		return nil, fmt.Errorf("unknown UpperType: %v", .UpperType)
	}

	 = append(, )

	var  error

	if .LowerType != Unbounded {
		 := len()
		 = pgio.AppendInt32(, -1)

		,  = .Lower.EncodeBinary(, )
		if  != nil {
			return nil, 
		}
		if  == nil {
			return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded")
		}

		pgio.SetInt32([:], int32(len([:])-4))
	}

	if .UpperType != Unbounded {
		 := len()
		 = pgio.AppendInt32(, -1)

		,  = .Upper.EncodeBinary(, )
		if  != nil {
			return nil, 
		}
		if  == nil {
			return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded")
		}

		pgio.SetInt32([:], int32(len([:])-4))
	}

	return , nil
}
Scan implements the database/sql Scanner interface.
func ( *Int4range) ( interface{}) error {
	if  == nil {
		* = Int4range{Status: Null}
		return nil
	}

	switch src := .(type) {
	case string:
		return .DecodeText(nil, []byte())
	case []byte:
		 := make([]byte, len())
		copy(, )
		return .DecodeText(nil, )
	}

	return fmt.Errorf("cannot scan %T", )
}
Value implements the database/sql/driver Valuer interface.
func ( Int4range) () (driver.Value, error) {
	return EncodeValueText()