package pgtype

import (
	
	
	
	
)

type Bool struct {
	Bool   bool
	Status Status
}

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

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

	switch value := .(type) {
	case bool:
		* = Bool{Bool: , Status: Present}
	case string:
		,  := strconv.ParseBool()
		if  != nil {
			return 
		}
		* = Bool{Bool: , Status: Present}
	case *bool:
		if  == nil {
			* = Bool{Status: Null}
		} else {
			return .(*)
		}
	case *string:
		if  == nil {
			* = Bool{Status: Null}
		} else {
			return .(*)
		}
	default:
		if ,  := underlyingBoolType();  {
			return .()
		}
		return fmt.Errorf("cannot convert %v to Bool", )
	}

	return nil
}

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

func ( *Bool) ( interface{}) error {
	switch .Status {
	case Present:
		switch v := .(type) {
		case *bool:
			* = .Bool
			return nil
		default:
			if ,  := GetAssignToDstType();  {
				return .()
			}
			return fmt.Errorf("unable to assign to %T", )
		}
	case Null:
		return NullAssignTo()
	}

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

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

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

	* = Bool{Bool: [0] == 't', Status: Present}
	return nil
}

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

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

	* = Bool{Bool: [0] == 1, Status: Present}
	return nil
}

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

	if .Bool {
		 = append(, 't')
	} else {
		 = append(, 'f')
	}

	return , nil
}

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

	if .Bool {
		 = append(, 1)
	} else {
		 = append(, 0)
	}

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

	switch src := .(type) {
	case bool:
		* = Bool{Bool: , 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 ( Bool) () (driver.Value, error) {
	switch .Status {
	case Present:
		return .Bool, nil
	case Null:
		return nil, nil
	default:
		return nil, errUndefined
	}
}

func ( Bool) () ([]byte, error) {
	switch .Status {
	case Present:
		if .Bool {
			return []byte("true"), nil
		} else {
			return []byte("false"), nil
		}
	case Null:
		return []byte("null"), nil
	case Undefined:
		return nil, errUndefined
	}

	return nil, errBadStatus
}

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

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

	return nil