package pgtype

import (
	
	
	
	
	
	

	
)

type Int4 struct {
	Int    int32
	Status Status
}

func ( *Int4) ( interface{}) error {
	if  == nil {
		* = Int4{Status: Null}
		return nil
	}

	if ,  := .(interface{ () interface{} });  {
		 := .()
		if  !=  {
			return .()
		}
	}

	switch value := .(type) {
	case int8:
		* = Int4{Int: int32(), Status: Present}
	case uint8:
		* = Int4{Int: int32(), Status: Present}
	case int16:
		* = Int4{Int: int32(), Status: Present}
	case uint16:
		* = Int4{Int: int32(), Status: Present}
	case int32:
		* = Int4{Int: int32(), Status: Present}
	case uint32:
		if  > math.MaxInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case int64:
		if  < math.MinInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		if  > math.MaxInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case uint64:
		if  > math.MaxInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case int:
		if  < math.MinInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		if  > math.MaxInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case uint:
		if  > math.MaxInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case string:
		,  := strconv.ParseInt(, 10, 32)
		if  != nil {
			return 
		}
		* = Int4{Int: int32(), Status: Present}
	case float32:
		if  > math.MaxInt32 {
			return fmt.Errorf("%f is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case float64:
		if  > math.MaxInt32 {
			return fmt.Errorf("%f is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
	case *int8:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *uint8:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *int16:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *uint16:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *int32:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *uint32:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *int64:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *uint64:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *int:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *uint:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *string:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *float32:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	case *float64:
		if  == nil {
			* = Int4{Status: Null}
		} else {
			return .(*)
		}
	default:
		if ,  := underlyingNumberType();  {
			return .()
		}
		return fmt.Errorf("cannot convert %v to Int4", )
	}

	return nil
}

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

func ( *Int4) ( interface{}) error {
	return int64AssignTo(int64(.Int), .Status, )
}

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

	,  := strconv.ParseInt(string(), 10, 32)
	if  != nil {
		return 
	}

	* = Int4{Int: int32(), Status: Present}
	return nil
}

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

	if len() != 4 {
		return fmt.Errorf("invalid length for int4: %v", len())
	}

	 := int32(binary.BigEndian.Uint32())
	* = Int4{Int: , Status: Present}
	return nil
}

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

	return append(, strconv.FormatInt(int64(.Int), 10)...), nil
}

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

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

	switch src := .(type) {
	case int64:
		if  < math.MinInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		if  > math.MaxInt32 {
			return fmt.Errorf("%d is greater than maximum value for Int4", )
		}
		* = Int4{Int: int32(), Status: Present}
		return nil
	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 ( Int4) () (driver.Value, error) {
	switch .Status {
	case Present:
		return int64(.Int), nil
	case Null:
		return nil, nil
	default:
		return nil, errUndefined
	}
}

func ( Int4) () ([]byte, error) {
	switch .Status {
	case Present:
		return []byte(strconv.FormatInt(int64(.Int), 10)), nil
	case Null:
		return []byte("null"), nil
	case Undefined:
		return nil, errUndefined
	}

	return nil, errBadStatus
}

func ( *Int4) ( []byte) error {
	var  *int32
	 := json.Unmarshal(, &)
	if  != nil {
		return 
	}

	if  == nil {
		* = Int4{Status: Null}
	} else {
		* = Int4{Int: *, Status: Present}
	}

	return nil