// DefaultTypeForValue returns the default FieldType for the value.
352057
func DefaultTypeForValue(value interface{}, tp *FieldType) {
	switch x := value.(type) {
	case nil:
		tp.Tp = mysql.TypeNull
	case bool, int64, int:
		tp.Tp = mysql.TypeLonglong
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case uint64:
		tp.Tp = mysql.TypeLonglong
		tp.Flag |= mysql.UnsignedFlag
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case string:
		tp.Tp = mysql.TypeVarString
		tp.Charset = mysql.DefaultCharset
		tp.Collate = mysql.DefaultCollationName
	case float64:
		tp.Tp = mysql.TypeDouble
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case []byte:
		tp.Tp = mysql.TypeBlob
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case Bit:
		tp.Tp = mysql.TypeBit
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case Hex:
		tp.Tp = mysql.TypeVarchar
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case Time:
		tp.Tp = x.Type
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case Duration:
		tp.Tp = mysql.TypeDuration
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case *MyDecimal:
		tp.Tp = mysql.TypeNewDecimal
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case Enum:
		tp.Tp = mysql.TypeEnum
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	case Set:
		tp.Tp = mysql.TypeSet
		tp.Charset = charset.CharsetBin
		tp.Collate = charset.CharsetBin
	default:
		tp.Tp = mysql.TypeDecimal
	}
	tp.Flen = UnspecifiedLength
	tp.Decimal = UnspecifiedLength
}
417853
func (s *ParameterDeclaration) SetDefaultValue(v string) *ParameterDeclaration {
	s.DefaultValue = &v
	return s
}
720840
func (s *Schema) DefaultValue() (interface{}, error) {
	if s.Default != nil {
		return s.Default, nil
	}

	if s.DefaultFunc != nil {
		defaultValue, err := s.DefaultFunc()
		if err != nil {
			return nil, fmt.Errorf("error loading default: %s", err)
		}
		return defaultValue, nil
	}

	return nil, nil
}
988459
func (s *StringRule) Default() ctypes.ConfigValue {
	if s.default_ != nil {
		return ctypes.ConfigValueStr{Value: *s.default_}
	}
	return nil
}
905935
func defaultResolveTypeFn(p ResolveTypeParams, abstractType Abstract) *Object {
	possibleTypes := p.Info.Schema.PossibleTypes(abstractType)
	for _, possibleType := range possibleTypes {
		if possibleType.IsTypeOf == nil {
			continue
		}
		isTypeOfParams := IsTypeOfParams{
			Value:   p.Value,
			Info:    p.Info,
			Context: p.Context,
		}
		if res := possibleType.IsTypeOf(isTypeOfParams); res {
			return possibleType
		}
	}
	return nil
}
246057
func defaultValue(char *gen.CharacteristicMetadata) interface{} {
	if isReadable(char) == false {
		return nil
	}

	switch char.Format {
	case "string":
		return `""`
	case "bool":
		return "false"
	case "int", "float", "uint8", "uint16", "uint32", "int32", "uint64":
		if min := minValue(char); min != nil {
			return min
		}

		return 0
	case "tlv8":
		return "[]byte{}"
	default:
		break
	}

	return nil
}
168615
func formatDefaultConfigTabular(writer io.Writer, value interface{}) error {
	defaultValues, ok := value.(config.ModelDefaultAttributes)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", defaultValues, value)
	}

	tw := output.TabWriter(writer)
	w := output.Wrapper{tw}

	p := func(name string, value config.AttributeDefaultValues) {
		var c, d interface{}
		switch value.Default {
		case nil:
			d = "-"
		case "":
			d = `""`
		default:
			d = value.Default
		}
		switch value.Controller {
		case nil:
			c = "-"
		case "":
			c = `""`
		default:
			c = value.Controller
		}
		w.Println(name, d, c)
		for _, region := range value.Regions {
			w.Println("  "+region.Name, region.Value, "-")
		}
	}
	var valueNames []string
	for name := range defaultValues {
		valueNames = append(valueNames, name)
	}
	sort.Strings(valueNames)

	w.Println("Attribute", "Default", "Controller")

	for _, name := range valueNames {
		info := defaultValues[name]
		out := &bytes.Buffer{}
		err := cmd.FormatYaml(out, info)
		if err != nil {
			return errors.Annotatef(err, "formatting value for %q", name)
		}
		p(name, info)
	}

	tw.Flush()
	return nil
}
1122056
func (s *DateArrayOptions) SetDefaultValue(v string) *DateArrayOptions {
	s.DefaultValue = &v
	return s
}
1323801
func genericValue(v Value) interface{} {
	if g, ok := v.(*generic); ok {
		return g.p
	}
	return nil
}
186396
func FillDefaultFrom(defaultsList ...interface{}) interface{} {
	if len(defaultsList) == 0 {
		return nil
	}

	rootType := reflect.TypeOf(defaultsList[0])
	if rootType.Kind() != reflect.Ptr {
		panic(fmt.Sprintf("FillDefaultsFrom only takes pointer types, not %s", rootType))
	}
	typeToMake := rootType.Elem()

	existing := reflect.New(typeToMake).Interface()
	existingVal := reflect.ValueOf(existing).Elem()
	existingType := reflect.TypeOf(existing)
	for _, defaults := range defaultsList {
		if defaults == nil {
			continue
		}
		defaultType := reflect.TypeOf(defaults)
		if defaultType != existingType {
			panic(fmt.Sprintf("Uncompatible types %s vs %s", existingType, defaultType))
		}
		defaultsVal := reflect.ValueOf(defaults)
		if defaultsVal.IsNil() {
			continue
		}
		defaultsVal = defaultsVal.Elem()
		singleItemCopy(existingVal, defaultsVal)
	}
	return existing
}
696532
func fieldValue(fieldVal reflect.Value, structField reflect.StructField) (ret interface{}) {
	if isBlank(fieldVal) {
		defaultValue := strings.TrimSpace(parseTagSetting(structField.Tag.Get("sql"))["default"])
		if defaultValue != "" {
			switch fieldVal.Kind() {
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				if numericValue, err := strconv.ParseInt(defaultValue, 10, 64); err == nil {
					if numericValue != fieldVal.Int() {
						return fieldVal.Int()
					}
					return numericValue
				}
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				if numericValue, err := strconv.ParseUint(defaultValue, 10, 64); err == nil {
					if numericValue != fieldVal.Uint() {
						return fieldVal.Int()
					}
					return numericValue
				}
			case reflect.Float32, reflect.Float64:
				if floatValue, err := strconv.ParseFloat(defaultValue, 64); err == nil {
					if floatValue != fieldVal.Float() {
						return fieldVal.Float()
					}
					return floatValue
				}
			case reflect.Bool:
				if boolValue, err := strconv.ParseBool(defaultValue); err == nil {
					if boolValue != fieldVal.Bool() {
						return fieldVal.Bool()
					}
					return boolValue
				}
			case reflect.String:
				return fieldVal.String()
			default:
				return nil
			}
		}
		return nil
	}
	return fieldVal.Interface()
}
228256
func (a *ArgClause) Default(values ...string) *ArgClause {
	a.defaultValues = values
	return a
}
1362490
func (s *HashAlgorithmOptions) SetDefaultValue(v string) *HashAlgorithmOptions {
	s.DefaultValue = &v
	return s
}
415595
func (i *IntRule) Default() ctypes.ConfigValue {
	if i.default_ != nil {
		return ctypes.ConfigValueInt{Value: *i.default_}
	}
	return nil
}
482376
func (m *Manager) SetDefaultValue(name string, value interface{}) {
	coverOption(m.defaults, name, value)
}
1402
func (s *IntArrayOptions) SetDefaultValue(v int64) *IntArrayOptions {
	s.DefaultValue = &v
	return s
}
426147
func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMessage bool, err error) {
	var canHaveDefault bool
	switch ft.Kind() {
	case reflect.Ptr:
		if ft.Elem().Kind() == reflect.Struct {
			nestedMessage = true
		} else {
			canHaveDefault = true // proto2 scalar field
		}

	case reflect.Slice:
		switch ft.Elem().Kind() {
		case reflect.Ptr:
			nestedMessage = true // repeated message
		case reflect.Uint8:
			canHaveDefault = true // bytes field
		}

	case reflect.Map:
		if ft.Elem().Kind() == reflect.Ptr {
			nestedMessage = true // map with message values
		}
	}

	if !canHaveDefault {
		if nestedMessage {
			return nil, true, nil
		}
		return nil, false, nil
	}

	// We now know that ft is a pointer or slice.
	sf = &scalarField{kind: ft.Elem().Kind()}

	// scalar fields without defaults
	if !prop.HasDefault {
		return sf, false, nil
	}

	// a scalar field: either *T or []byte
	switch ft.Elem().Kind() {
	case reflect.Bool:
		x, err := strconv.ParseBool(prop.Default)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default bool %q: %v", prop.Default, err)
		}
		sf.value = x
	case reflect.Float32:
		x, err := strconv.ParseFloat(prop.Default, 32)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default float32 %q: %v", prop.Default, err)
		}
		sf.value = float32(x)
	case reflect.Float64:
		x, err := strconv.ParseFloat(prop.Default, 64)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default float64 %q: %v", prop.Default, err)
		}
		sf.value = x
	case reflect.Int32:
		x, err := strconv.ParseInt(prop.Default, 10, 32)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default int32 %q: %v", prop.Default, err)
		}
		sf.value = int32(x)
	case reflect.Int64:
		x, err := strconv.ParseInt(prop.Default, 10, 64)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default int64 %q: %v", prop.Default, err)
		}
		sf.value = x
	case reflect.String:
		sf.value = prop.Default
	case reflect.Uint8:
		// []byte (not *uint8)
		sf.value = []byte(prop.Default)
	case reflect.Uint32:
		x, err := strconv.ParseUint(prop.Default, 10, 32)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default uint32 %q: %v", prop.Default, err)
		}
		sf.value = uint32(x)
	case reflect.Uint64:
		x, err := strconv.ParseUint(prop.Default, 10, 64)
		if err != nil {
			return nil, false, fmt.Errorf("proto: bad default uint64 %q: %v", prop.Default, err)
		}
		sf.value = x
	default:
		return nil, false, fmt.Errorf("proto: unhandled def kind %v", ft.Elem().Kind())
	}

	return sf, false, nil
}