// HCL2ValueFromConfigValue is the opposite of configValueFromHCL2: it takes
// a value as would be returned from the old interpolator and turns it into
// a cty.Value so it can be used within, for example, an HCL2 EvalContext.
163696
func HCL2ValueFromConfigValue(v interface{}) cty.Value {
	if v == nil {
		return cty.NullVal(cty.DynamicPseudoType)
	}
	if v == UnknownVariableValue {
		return cty.DynamicVal
	}

	switch tv := v.(type) {
	case bool:
		return cty.BoolVal(tv)
	case string:
		return cty.StringVal(tv)
	case int:
		return cty.NumberIntVal(int64(tv))
	case float64:
		return cty.NumberFloatVal(tv)
	case []interface{}:
		vals := make([]cty.Value, len(tv))
		for i, ev := range tv {
			vals[i] = HCL2ValueFromConfigValue(ev)
		}
		return cty.TupleVal(vals)
	case map[string]interface{}:
		vals := map[string]cty.Value{}
		for k, ev := range tv {
			vals[k] = HCL2ValueFromConfigValue(ev)
		}
		return cty.ObjectVal(vals)
	default:
		// HCL/HIL should never generate anything that isn't caught by
		// the above, so if we get here something has gone very wrong.
		panic(fmt.Errorf("can't convert %#v to cty.Value", v))
	}
}
478433
func newValueExpr(value interface{}) ast.ValueExpr {
	if ve, ok := value.(*ValueExpr); ok {
		return ve
	}
	ve := &ValueExpr{}
	ve.SetValue(value)
	types.DefaultTypeForValue(value, &ve.Type)
	ve.projectionOffset = -1
	return ve
}
175682
func (arc *ConfigFactory) GetValue(key string) cast.Value {
	if arc.initSuccess == false {
		return nil
	}

	var confValue cast.Value
	val := arc.GetConfigurationByKey(key)
	if val == nil {
		confValue = cast.NewValue(nil, errors.New("key does not exist"))
	} else {
		confValue = cast.NewValue(val, nil)
	}

	return confValue
}
891657
func NewValueExpr(value interface{}) *ValueExpr {
	if ve, ok := value.(*ValueExpr); ok {
		return ve
	}
	ve := &ValueExpr{}
	ve.SetValue(value)
	types.DefaultTypeForValue(value, &ve.Type)
	return ve
}
456294
func CapabilitiesValue(capabilities map[string]bool) *StandardConfigValue {
	c := &cb.Capabilities{
		Capabilities: make(map[string]*cb.Capability),
	}

	for capability, required := range capabilities {
		if !required {
			continue
		}
		c.Capabilities[capability] = &cb.Capability{}
	}

	return &StandardConfigValue{
		key:   CapabilitiesKey,
		value: c,
	}
}
1373492
func ChannelRestrictionsValue(maxChannelCount uint64) *StandardConfigValue {
	return &StandardConfigValue{
		key: ChannelRestrictionsKey,
		value: &ab.ChannelRestrictions{
			MaxCount: maxChannelCount,
		},
	}
}
798134
func (r *ReferenceConstraint) DefaultValue() interface{} {
	c, err := r.Resolved()
	if err != nil {
		return nil
	}
	return c.DefaultValue()
}
1032276
func ColValue(opt operator, value interface{}) interface{} {
	switch opt {
	case ColAdd, ColMinus, ColMultiply, ColExcept:
	default:
		panic(fmt.Errorf("orm.ColValue wrong operator"))
	}
	v, err := StrTo(ToStr(value)).Int64()
	if err != nil {
		panic(fmt.Errorf("orm.ColValue doesn't support non string/numeric type, %s", err))
	}
	var val colValue
	val.value = v
	val.opt = opt
	return val
}
1323801
func genericValue(v Value) interface{} {
	if g, ok := v.(*generic); ok {
		return g.p
	}
	return nil
}
483442
func (b *NestedBlock) EmptyValue() cty.Value {
	switch b.Nesting {
	case NestingSingle:
		return cty.NullVal(b.Block.ImpliedType())
	case NestingGroup:
		return b.Block.EmptyValue()
	case NestingList:
		if ty := b.Block.ImpliedType(); ty.HasDynamicTypes() {
			return cty.EmptyTupleVal
		} else {
			return cty.ListValEmpty(ty)
		}
	case NestingMap:
		if ty := b.Block.ImpliedType(); ty.HasDynamicTypes() {
			return cty.EmptyObjectVal
		} else {
			return cty.MapValEmpty(ty)
		}
	case NestingSet:
		return cty.SetValEmpty(b.Block.ImpliedType())
	default:
		// Should never get here because the above is intended to be exhaustive,
		// but we'll be robust and return a result nonetheless.
		return cty.NullVal(cty.DynamicPseudoType)
	}
}
976444
func getConfigItemValue(item ctypes.ConfigValue) (interface{}, error) {

	var value interface{}

	switch item.Type() {
	case "string":
		value = item.(ctypes.ConfigValueStr).Value
		break

	case "float":
		value = item.(ctypes.ConfigValueFloat).Value
		break

	case "integer":
		value = item.(ctypes.ConfigValueInt).Value
		break

	case "bool":
		value = item.(ctypes.ConfigValueBool).Value
		break

	default:
		return nil, fmt.Errorf("Unsupported type of configuration item, type=%v", item.Type())
	}

	return value, 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
}
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
}
1267434
func NewValue(val interface{}, err error) Value {
	confVal := new(configValue)
	confVal.value = val
	confVal.err = err
	return confVal
}
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
}
212056
func (s *Secret) SetValueFrom(v string) *Secret {
	s.ValueFrom = &v
	return s
}
576478
func (r *RawConfig) Value() interface{} {
	if c := r.Config(); c != nil {
		if v, ok := c[r.Key]; ok {
			return v
		}
	}

	r.lock.Lock()
	defer r.lock.Unlock()
	return r.Raw[r.Key]
}