package pgdialect

import (
	
	
	
	

	
	
)

func ( reflect.Type) schema.ScannerFunc {
	 := .Kind()

	switch  {
	case reflect.Ptr:
		if  := (.Elem());  != nil {
			return schema.PtrScanner()
		}
	case reflect.Slice, reflect.Array:
		// ok:
	default:
		return nil
	}

	 := .Elem()

	if  == reflect.Slice {
		switch  {
		case stringType:
			return scanStringSliceValue
		case intType:
			return scanIntSliceValue
		case int64Type:
			return scanInt64SliceValue
		case float64Type:
			return scanFloat64SliceValue
		}
	}

	 := schema.Scanner()
	return func( reflect.Value,  interface{}) error {
		 = reflect.Indirect()
		if !.CanSet() {
			return fmt.Errorf("bun: Scan(non-settable %s)", .Type())
		}

		 := .Kind()

		if  == nil {
			if  != reflect.Slice || !.IsNil() {
				.Set(reflect.Zero(.Type()))
			}
			return nil
		}

		if  == reflect.Slice {
			if .IsNil() {
				.Set(reflect.MakeSlice(.Type(), 0, 0))
			} else if .Len() > 0 {
				.Set(.Slice(0, 0))
			}
		}

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

		 := newArrayParser()
		 := internal.MakeSliceNextElemFunc()
		for {
			,  := .NextElem()
			if  != nil {
				if  == io.EOF {
					break
				}
				return 
			}

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

		return nil
	}
}

func ( reflect.Value,  interface{}) error {
	 = reflect.Indirect()
	if !.CanSet() {
		return fmt.Errorf("bun: Scan(non-settable %s)", .Type())
	}

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

	.Set(reflect.ValueOf())
	return nil
}

func ( interface{}) ([]string, error) {
	if  == nil {
		return nil, nil
	}

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

	 := make([]string, 0)

	 := newArrayParser()
	for {
		,  := .NextElem()
		if  != nil {
			if  == io.EOF {
				break
			}
			return nil, 
		}
		 = append(, string())
	}

	return , nil
}

func ( reflect.Value,  interface{}) error {
	 = reflect.Indirect()
	if !.CanSet() {
		return fmt.Errorf("bun: Scan(non-settable %s)", .Type())
	}

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

	.Set(reflect.ValueOf())
	return nil
}

func ( interface{}) ([]int, error) {
	if  == nil {
		return nil, nil
	}

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

	 := make([]int, 0)

	 := newArrayParser()
	for {
		,  := .NextElem()
		if  != nil {
			if  == io.EOF {
				break
			}
			return nil, 
		}

		if  == nil {
			 = append(, 0)
			continue
		}

		,  := strconv.Atoi(bytesToString())
		if  != nil {
			return nil, 
		}

		 = append(, )
	}

	return , nil
}

func ( reflect.Value,  interface{}) error {
	 = reflect.Indirect()
	if !.CanSet() {
		return fmt.Errorf("bun: Scan(non-settable %s)", .Type())
	}

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

	.Set(reflect.ValueOf())
	return nil
}

func ( interface{}) ([]int64, error) {
	if  == nil {
		return nil, nil
	}

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

	 := make([]int64, 0)

	 := newArrayParser()
	for {
		,  := .NextElem()
		if  != nil {
			if  == io.EOF {
				break
			}
			return nil, 
		}

		if  == nil {
			 = append(, 0)
			continue
		}

		,  := strconv.ParseInt(bytesToString(), 10, 64)
		if  != nil {
			return nil, 
		}

		 = append(, )
	}

	return , nil
}

func ( reflect.Value,  interface{}) error {
	 = reflect.Indirect()
	if !.CanSet() {
		return fmt.Errorf("bun: Scan(non-settable %s)", .Type())
	}

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

	.Set(reflect.ValueOf())
	return nil
}

func ( interface{}) ([]float64, error) {
	if  == -1 {
		return nil, nil
	}

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

	 := make([]float64, 0)

	 := newArrayParser()
	for {
		,  := .NextElem()
		if  != nil {
			if  == io.EOF {
				break
			}
			return nil, 
		}

		if  == nil {
			 = append(, 0)
			continue
		}

		,  := strconv.ParseFloat(bytesToString(), 64)
		if  != nil {
			return nil, 
		}

		 = append(, )
	}

	return , nil
}

func ( interface{}) ([]byte, error) {
	switch src := .(type) {
	case string:
		return stringToBytes(), nil
	case []byte:
		return , nil
	default:
		return nil, fmt.Errorf("bun: got %T, wanted []byte or string", )
	}
}