// SetBuilderElementValue if it will change to struct from map if the future's
// author is feeling a bothersome in this function.
428841
func SetBuilderElementValue(elm *etree.Element, data [][]interface{}, basekey string) (*etree.Element, bool) {
	var child *etree.Element

	key := basekey
	ts, tk := spaceDecompose(elm.Tag)
	_, sk := spaceDecompose(elm.Space)

	if elm.Tag != "" && ts != "" && tk != "" {
		key = fmt.Sprintf("%s:%s", elm.Space, basekey)
	} else if sk != "" {
		key = fmt.Sprintf("%s:%s", sk, basekey)
	}

	var values interface{}
	var found bool
	for _, v := range data {
		if v[0] == basekey {
			values = v[1]
			found = true
			break
		}
	}
	if !found {
		return child, false
	}

	switch value := values.(type) {
	case nil:
	default:
		child = elm.CreateElement(key)
		child.SetText(fmt.Sprint(value))
	case int:
		child = elm.CreateElement(key)
		child.SetText(fmt.Sprint(value))
	case string:
		child = elm.CreateElement(key)
		child.SetText(value)
	case float64, float32:
		child = elm.CreateElement(key)
		child.SetText(fmt.Sprint(value))
	case time.Time:
		child = elm.CreateElement(key)
		child.SetText(value.Format(time.RFC3339))
	case bool:
		_ = elm.CreateElement(fmt.Sprintf("%s:%s", key, key))
	case []int:
		for _, v := range value {
			child = elm.CreateElement(key)
			child.SetText(fmt.Sprint(v))
		}
	case []string:
		for _, v := range value {
			child = elm.CreateElement(key)
			child.SetText(v)
		}
	case []Attr:
		for _, attr := range value {
			child = elm.CreateElement(key)
			for k, v := range attr {
				child.CreateAttr(k, v)
			}
		}
	case Attrs:
		val, attrs := value[0], value[1]

		child, _ = SetBuilderElementValue(elm, URL{[]interface{}{basekey, val}}, basekey)
		switch attr := attrs.(type) {
		case map[string]string:
			for k, v := range attr {
				child.CreateAttr(k, v)
			}
		// TODO: gotta remove below
		case Attr:
			for k, v := range attr {
				child.CreateAttr(k, v)
			}
		}

	case interface{}:
		var childkey string
		if sk == "" {
			childkey = fmt.Sprintf("%s:%s", key, key)
		} else {
			childkey = fmt.Sprint(key)
		}

		switch value := values.(type) {
		case []URL:
			for _, val := range value {
				child := elm.CreateElement(childkey)
				for _, v := range val {
					SetBuilderElementValue(child, val, v[0].(string))
				}
			}
		case URL:
			child := elm.CreateElement(childkey)
			for _, v := range value {
				SetBuilderElementValue(child, value, v[0].(string))
			}
		}
	}
	return child, true
}
528085
func (s *DeleteImageBuilderOutput) SetImageBuilder(v *ImageBuilder) *DeleteImageBuilderOutput {
	s.ImageBuilder = v
	return s
}
1326833
func (p *propServerPlan) SetServerPlanByValue(cpu int, memoryGB int, gen PlanGenerations) {
	plan := &ProductServer{}
	plan.CPU = cpu
	plan.SetMemoryGB(memoryGB)
	plan.Generation = gen
	p.ServerPlan = plan
}
790463
func (s *Contributor) SetValue(v int64) *Contributor {
	s.Value = &v
	return s
}
324283
func (a *EvaluateArgs) SetReturnByValue(returnByValue bool) *EvaluateArgs {
	a.ReturnByValue = &returnByValue
	return a
}
1038152
func (f *fragment) setValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) {
	return f.setValueBase(columnID, bitDepth, value, false)
}
805703
func (f *Field) SetValue(columnID uint64, value int64) (changed bool, err error) {
	// Fetch bsiGroup and validate value.
	bsig := f.bsiGroup(f.name)
	if bsig == nil {
		return false, ErrBSIGroupNotFound
	} else if value < bsig.Min {
		return false, ErrBSIGroupValueTooLow
	} else if value > bsig.Max {
		return false, ErrBSIGroupValueTooHigh
	}

	// Fetch target view.
	view, err := f.createViewIfNotExists(viewBSIGroupPrefix + f.name)
	if err != nil {
		return false, errors.Wrap(err, "creating view")
	}

	// Determine base value to store.
	baseValue := uint64(value - bsig.Min)

	return view.setValue(columnID, bsig.BitDepth(), baseValue)
}
929776
func (c *Ctx) SetAttributeValue(sh SessionHandle, o ObjectHandle, a []*Attribute) error {
	arena, pa, palen := cAttributeList(a)
	defer arena.Free()
	e := C.SetAttributeValue(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(o), pa, palen)
	return toError(e)
}
925671
func (c *keyValueChanger) SetValue(value interface{}) (interface{}, error) {
	if c.err != nil {
		return nil, c.err
	}
	current := c.node.content.value()
	c.node.content = keyValue{c.node.content.key(), value}
	return current, nil
}
628532
func (s *EventFilter) SetEntityValues(v []*string) *EventFilter {
	s.EntityValues = v
	return s
}
237352
func (s *EntityFilter) SetEntityValues(v []*string) *EntityFilter {
	s.EntityValues = v
	return s
}
1078530
func (s *AnnotationValue) SetNumberValue(v float64) *AnnotationValue {
	s.NumberValue = &v
	return s
}
1041180
func (s *RelationalDatabaseSnapshot) SetFromRelationalDatabaseName(v string) *RelationalDatabaseSnapshot {
	s.FromRelationalDatabaseName = &v
	return s
}
590736
func (d *dbBase) setFieldValue(fi *fieldInfo, value interface{}, field reflect.Value) (interface{}, error) {

	fieldType := fi.fieldType
	isNative := fi.isFielder == false

setValue:
	switch {
	case fieldType == TypeBooleanField:
		if isNative {
			if nb, ok := field.Interface().(sql.NullBool); ok {
				if value == nil {
					nb.Valid = false
				} else {
					nb.Bool = value.(bool)
					nb.Valid = true
				}
				field.Set(reflect.ValueOf(nb))
			} else if field.Kind() == reflect.Ptr {
				if value != nil {
					v := value.(bool)
					field.Set(reflect.ValueOf(&v))
				}
			} else {
				if value == nil {
					value = false
				}
				field.SetBool(value.(bool))
			}
		}
	case fieldType == TypeCharField || fieldType == TypeTextField:
		if isNative {
			if ns, ok := field.Interface().(sql.NullString); ok {
				if value == nil {
					ns.Valid = false
				} else {
					ns.String = value.(string)
					ns.Valid = true
				}
				field.Set(reflect.ValueOf(ns))
			} else if field.Kind() == reflect.Ptr {
				if value != nil {
					v := value.(string)
					field.Set(reflect.ValueOf(&v))
				}
			} else {
				if value == nil {
					value = ""
				}
				field.SetString(value.(string))
			}
		}
	case fieldType == TypeDateField || fieldType == TypeDateTimeField:
		if isNative {
			if value == nil {
				value = time.Time{}
			}
			field.Set(reflect.ValueOf(value))
		}
	case fieldType == TypePositiveBitField && field.Kind() == reflect.Ptr:
		if value != nil {
			v := uint8(value.(uint64))
			field.Set(reflect.ValueOf(&v))
		}
	case fieldType == TypePositiveSmallIntegerField && field.Kind() == reflect.Ptr:
		if value != nil {
			v := uint16(value.(uint64))
			field.Set(reflect.ValueOf(&v))
		}
	case fieldType == TypePositiveIntegerField && field.Kind() == reflect.Ptr:
		if value != nil {
			if field.Type() == reflect.TypeOf(new(uint)) {
				v := uint(value.(uint64))
				field.Set(reflect.ValueOf(&v))
			} else {
				v := uint32(value.(uint64))
				field.Set(reflect.ValueOf(&v))
			}
		}
	case fieldType == TypePositiveBigIntegerField && field.Kind() == reflect.Ptr:
		if value != nil {
			v := value.(uint64)
			field.Set(reflect.ValueOf(&v))
		}
	case fieldType == TypeBitField && field.Kind() == reflect.Ptr:
		if value != nil {
			v := int8(value.(int64))
			field.Set(reflect.ValueOf(&v))
		}
	case fieldType == TypeSmallIntegerField && field.Kind() == reflect.Ptr:
		if value != nil {
			v := int16(value.(int64))
			field.Set(reflect.ValueOf(&v))
		}
	case fieldType == TypeIntegerField && field.Kind() == reflect.Ptr:
		if value != nil {
			if field.Type() == reflect.TypeOf(new(int)) {
				v := int(value.(int64))
				field.Set(reflect.ValueOf(&v))
			} else {
				v := int32(value.(int64))
				field.Set(reflect.ValueOf(&v))
			}
		}
	case fieldType == TypeBigIntegerField && field.Kind() == reflect.Ptr:
		if value != nil {
			v := value.(int64)
			field.Set(reflect.ValueOf(&v))
		}
	case fieldType&IsIntegerField > 0:
		if fieldType&IsPostiveIntegerField > 0 {
			if isNative {
				if value == nil {
					value = uint64(0)
				}
				field.SetUint(value.(uint64))
			}
		} else {
			if isNative {
				if ni, ok := field.Interface().(sql.NullInt64); ok {
					if value == nil {
						ni.Valid = false
					} else {
						ni.Int64 = value.(int64)
						ni.Valid = true
					}
					field.Set(reflect.ValueOf(ni))
				} else {
					if value == nil {
						value = int64(0)
					}
					field.SetInt(value.(int64))
				}
			}
		}
	case fieldType == TypeFloatField || fieldType == TypeDecimalField:
		if isNative {
			if nf, ok := field.Interface().(sql.NullFloat64); ok {
				if value == nil {
					nf.Valid = false
				} else {
					nf.Float64 = value.(float64)
					nf.Valid = true
				}
				field.Set(reflect.ValueOf(nf))
			} else if field.Kind() == reflect.Ptr {
				if value != nil {
					if field.Type() == reflect.TypeOf(new(float32)) {
						v := float32(value.(float64))
						field.Set(reflect.ValueOf(&v))
					} else {
						v := value.(float64)
						field.Set(reflect.ValueOf(&v))
					}
				}
			} else {

				if value == nil {
					value = float64(0)
				}
				field.SetFloat(value.(float64))
			}
		}
	case fieldType&IsRelField > 0:
		if value != nil {
			fieldType = fi.relModelInfo.fields.pk.fieldType
			mf := reflect.New(fi.relModelInfo.addrField.Elem().Type())
			field.Set(mf)
			f := mf.Elem().Field(fi.relModelInfo.fields.pk.fieldIndex)
			field = f
			goto setValue
		}
	}

	if isNative == false {
		fd := field.Addr().Interface().(Fielder)
		err := fd.SetRaw(value)
		if err != nil {
			err = fmt.Errorf("converted value `%v` set to Fielder `%s` failed, err: %s", value, fi.fullName, err)
			return nil, err
		}
	}

	return value, nil
}
354770
func (s *StopImageBuilderOutput) SetImageBuilder(v *ImageBuilder) *StopImageBuilderOutput {
	s.ImageBuilder = v
	return s
}
86497
func (s *RemediationParameterValue) SetResourceValue(v *ResourceValue) *RemediationParameterValue {
	s.ResourceValue = v
	return s
}
1187285
func SetValueAtPath(i interface{}, path string, v interface{}) {
	if rvals := rValuesAtPath(i, path, true, false, v == nil); rvals != nil {
		for _, rval := range rvals {
			if rval.Kind() == reflect.Ptr && rval.IsNil() {
				continue
			}
			setValue(rval, v)
		}
	}
}