package callbacks

import (
	
	

	
	
)

// ConvertMapToValuesForCreate convert map to values
func ( *gorm.Statement,  map[string]interface{}) ( clause.Values) {
	.Columns = make([]clause.Column, 0, len())
	,  := .SelectAndOmitColumns(true, false)

	 := make([]string, 0, len())
	for  := range  {
		 = append(, )
	}
	sort.Strings()

	for ,  := range  {
		 := []
		if .Schema != nil {
			if  := .Schema.LookUpField();  != nil {
				 = .DBName
			}
		}

		if ,  := []; ( && ) || (! && !) {
			.Columns = append(.Columns, clause.Column{Name: })
			if len(.Values) == 0 {
				.Values = [][]interface{}{{}}
			}

			.Values[0] = append(.Values[0], )
		}
	}
	return
}

// ConvertSliceOfMapToValuesForCreate convert slice of map to values
func ( *gorm.Statement,  []map[string]interface{}) ( clause.Values) {
	 := make([]string, 0, len())

	// when the length of mapValues is zero,return directly here
	// no need to call stmt.SelectAndOmitColumns method
	if len() == 0 {
		.AddError(gorm.ErrEmptySlice)
		return
	}

	var (
		                    = make(map[string][]interface{}, len())
		,  = .SelectAndOmitColumns(true, false)
	)

	for ,  := range  {
		for ,  := range  {
			if .Schema != nil {
				if  := .Schema.LookUpField();  != nil {
					 = .DBName
				}
			}

			if ,  := []; ! {
				if ,  := []; ( && ) || (! && !) {
					[] = make([]interface{}, len())
					 = append(, )
				} else {
					continue
				}
			}

			[][] = 
		}
	}

	sort.Strings()
	.Values = make([][]interface{}, len())
	.Columns = make([]clause.Column, len())
	for ,  := range  {
		.Columns[] = clause.Column{Name: }

		for ,  := range [] {
			if len(.Values[]) == 0 {
				.Values[] = make([]interface{}, len())
			}

			.Values[][] = 
		}
	}
	return
}

func hasReturning( *gorm.DB,  bool) (bool, gorm.ScanMode) {
	if  {
		if ,  := .Statement.Clauses["RETURNING"];  {
			,  := .Expression.(clause.Returning)
			if len(.Columns) == 0 || (len(.Columns) == 1 && .Columns[0].Name == "*") {
				return true, 0
			}
			return true, gorm.ScanUpdate
		}
	}
	return false, 0
}

func checkMissingWhereConditions( *gorm.DB) {
	if !.AllowGlobalUpdate && .Error == nil {
		,  := .Statement.Clauses["WHERE"]
		if  {
			if ,  := .Statement.Clauses["soft_delete_enabled"];  {
				,  := .Expression.(clause.Where)
				 = len(.Exprs) > 1
			}
		}
		if ! {
			.AddError(gorm.ErrMissingWhereClause)
		}
		return
	}
}

type visitMap = map[reflect.Value]bool

// Check if circular values, return true if loaded
func loadOrStoreVisitMap( *visitMap,  reflect.Value) ( bool) {
	if .Kind() == reflect.Ptr {
		 = .Elem()
	}

	switch .Kind() {
	case reflect.Slice, reflect.Array:
		 = true
		for  := 0;  < .Len(); ++ {
			if !(, .Index()) {
				 = false
			}
		}
	case reflect.Struct, reflect.Interface:
		if .CanAddr() {
			 := .Addr()
			if ,  := (*)[];  {
				return true
			}
			(*)[] = true
		}
	}

	return
}