// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/cloudreve/Cloudreve/v4/ent/entity"
	"github.com/cloudreve/Cloudreve/v4/ent/file"
	"github.com/cloudreve/Cloudreve/v4/ent/group"
	"github.com/cloudreve/Cloudreve/v4/ent/node"
	"github.com/cloudreve/Cloudreve/v4/ent/predicate"
	"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
	"github.com/cloudreve/Cloudreve/v4/inventory/types"
)

// StoragePolicyUpdate is the builder for updating StoragePolicy entities.
type StoragePolicyUpdate struct {
	config
	hooks    []Hook
	mutation *StoragePolicyMutation
}

// Where appends a list predicates to the StoragePolicyUpdate builder.
func (spu *StoragePolicyUpdate) Where(ps ...predicate.StoragePolicy) *StoragePolicyUpdate {
	spu.mutation.Where(ps...)
	return spu
}

// SetUpdatedAt sets the "updated_at" field.
func (spu *StoragePolicyUpdate) SetUpdatedAt(t time.Time) *StoragePolicyUpdate {
	spu.mutation.SetUpdatedAt(t)
	return spu
}

// SetDeletedAt sets the "deleted_at" field.
func (spu *StoragePolicyUpdate) SetDeletedAt(t time.Time) *StoragePolicyUpdate {
	spu.mutation.SetDeletedAt(t)
	return spu
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableDeletedAt(t *time.Time) *StoragePolicyUpdate {
	if t != nil {
		spu.SetDeletedAt(*t)
	}
	return spu
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (spu *StoragePolicyUpdate) ClearDeletedAt() *StoragePolicyUpdate {
	spu.mutation.ClearDeletedAt()
	return spu
}

// SetName sets the "name" field.
func (spu *StoragePolicyUpdate) SetName(s string) *StoragePolicyUpdate {
	spu.mutation.SetName(s)
	return spu
}

// SetNillableName sets the "name" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableName(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetName(*s)
	}
	return spu
}

// SetType sets the "type" field.
func (spu *StoragePolicyUpdate) SetType(s string) *StoragePolicyUpdate {
	spu.mutation.SetType(s)
	return spu
}

// SetNillableType sets the "type" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableType(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetType(*s)
	}
	return spu
}

// SetServer sets the "server" field.
func (spu *StoragePolicyUpdate) SetServer(s string) *StoragePolicyUpdate {
	spu.mutation.SetServer(s)
	return spu
}

// SetNillableServer sets the "server" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableServer(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetServer(*s)
	}
	return spu
}

// ClearServer clears the value of the "server" field.
func (spu *StoragePolicyUpdate) ClearServer() *StoragePolicyUpdate {
	spu.mutation.ClearServer()
	return spu
}

// SetBucketName sets the "bucket_name" field.
func (spu *StoragePolicyUpdate) SetBucketName(s string) *StoragePolicyUpdate {
	spu.mutation.SetBucketName(s)
	return spu
}

// SetNillableBucketName sets the "bucket_name" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableBucketName(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetBucketName(*s)
	}
	return spu
}

// ClearBucketName clears the value of the "bucket_name" field.
func (spu *StoragePolicyUpdate) ClearBucketName() *StoragePolicyUpdate {
	spu.mutation.ClearBucketName()
	return spu
}

// SetIsPrivate sets the "is_private" field.
func (spu *StoragePolicyUpdate) SetIsPrivate(b bool) *StoragePolicyUpdate {
	spu.mutation.SetIsPrivate(b)
	return spu
}

// SetNillableIsPrivate sets the "is_private" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableIsPrivate(b *bool) *StoragePolicyUpdate {
	if b != nil {
		spu.SetIsPrivate(*b)
	}
	return spu
}

// ClearIsPrivate clears the value of the "is_private" field.
func (spu *StoragePolicyUpdate) ClearIsPrivate() *StoragePolicyUpdate {
	spu.mutation.ClearIsPrivate()
	return spu
}

// SetAccessKey sets the "access_key" field.
func (spu *StoragePolicyUpdate) SetAccessKey(s string) *StoragePolicyUpdate {
	spu.mutation.SetAccessKey(s)
	return spu
}

// SetNillableAccessKey sets the "access_key" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableAccessKey(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetAccessKey(*s)
	}
	return spu
}

// ClearAccessKey clears the value of the "access_key" field.
func (spu *StoragePolicyUpdate) ClearAccessKey() *StoragePolicyUpdate {
	spu.mutation.ClearAccessKey()
	return spu
}

// SetSecretKey sets the "secret_key" field.
func (spu *StoragePolicyUpdate) SetSecretKey(s string) *StoragePolicyUpdate {
	spu.mutation.SetSecretKey(s)
	return spu
}

// SetNillableSecretKey sets the "secret_key" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableSecretKey(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetSecretKey(*s)
	}
	return spu
}

// ClearSecretKey clears the value of the "secret_key" field.
func (spu *StoragePolicyUpdate) ClearSecretKey() *StoragePolicyUpdate {
	spu.mutation.ClearSecretKey()
	return spu
}

// SetMaxSize sets the "max_size" field.
func (spu *StoragePolicyUpdate) SetMaxSize(i int64) *StoragePolicyUpdate {
	spu.mutation.ResetMaxSize()
	spu.mutation.SetMaxSize(i)
	return spu
}

// SetNillableMaxSize sets the "max_size" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableMaxSize(i *int64) *StoragePolicyUpdate {
	if i != nil {
		spu.SetMaxSize(*i)
	}
	return spu
}

// AddMaxSize adds i to the "max_size" field.
func (spu *StoragePolicyUpdate) AddMaxSize(i int64) *StoragePolicyUpdate {
	spu.mutation.AddMaxSize(i)
	return spu
}

// ClearMaxSize clears the value of the "max_size" field.
func (spu *StoragePolicyUpdate) ClearMaxSize() *StoragePolicyUpdate {
	spu.mutation.ClearMaxSize()
	return spu
}

// SetDirNameRule sets the "dir_name_rule" field.
func (spu *StoragePolicyUpdate) SetDirNameRule(s string) *StoragePolicyUpdate {
	spu.mutation.SetDirNameRule(s)
	return spu
}

// SetNillableDirNameRule sets the "dir_name_rule" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableDirNameRule(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetDirNameRule(*s)
	}
	return spu
}

// ClearDirNameRule clears the value of the "dir_name_rule" field.
func (spu *StoragePolicyUpdate) ClearDirNameRule() *StoragePolicyUpdate {
	spu.mutation.ClearDirNameRule()
	return spu
}

// SetFileNameRule sets the "file_name_rule" field.
func (spu *StoragePolicyUpdate) SetFileNameRule(s string) *StoragePolicyUpdate {
	spu.mutation.SetFileNameRule(s)
	return spu
}

// SetNillableFileNameRule sets the "file_name_rule" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableFileNameRule(s *string) *StoragePolicyUpdate {
	if s != nil {
		spu.SetFileNameRule(*s)
	}
	return spu
}

// ClearFileNameRule clears the value of the "file_name_rule" field.
func (spu *StoragePolicyUpdate) ClearFileNameRule() *StoragePolicyUpdate {
	spu.mutation.ClearFileNameRule()
	return spu
}

// SetSettings sets the "settings" field.
func (spu *StoragePolicyUpdate) SetSettings(ts *types.PolicySetting) *StoragePolicyUpdate {
	spu.mutation.SetSettings(ts)
	return spu
}

// ClearSettings clears the value of the "settings" field.
func (spu *StoragePolicyUpdate) ClearSettings() *StoragePolicyUpdate {
	spu.mutation.ClearSettings()
	return spu
}

// SetNodeID sets the "node_id" field.
func (spu *StoragePolicyUpdate) SetNodeID(i int) *StoragePolicyUpdate {
	spu.mutation.SetNodeID(i)
	return spu
}

// SetNillableNodeID sets the "node_id" field if the given value is not nil.
func (spu *StoragePolicyUpdate) SetNillableNodeID(i *int) *StoragePolicyUpdate {
	if i != nil {
		spu.SetNodeID(*i)
	}
	return spu
}

// ClearNodeID clears the value of the "node_id" field.
func (spu *StoragePolicyUpdate) ClearNodeID() *StoragePolicyUpdate {
	spu.mutation.ClearNodeID()
	return spu
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (spu *StoragePolicyUpdate) AddGroupIDs(ids ...int) *StoragePolicyUpdate {
	spu.mutation.AddGroupIDs(ids...)
	return spu
}

// AddGroups adds the "groups" edges to the Group entity.
func (spu *StoragePolicyUpdate) AddGroups(g ...*Group) *StoragePolicyUpdate {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return spu.AddGroupIDs(ids...)
}

// AddFileIDs adds the "files" edge to the File entity by IDs.
func (spu *StoragePolicyUpdate) AddFileIDs(ids ...int) *StoragePolicyUpdate {
	spu.mutation.AddFileIDs(ids...)
	return spu
}

// AddFiles adds the "files" edges to the File entity.
func (spu *StoragePolicyUpdate) AddFiles(f ...*File) *StoragePolicyUpdate {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return spu.AddFileIDs(ids...)
}

// AddEntityIDs adds the "entities" edge to the Entity entity by IDs.
func (spu *StoragePolicyUpdate) AddEntityIDs(ids ...int) *StoragePolicyUpdate {
	spu.mutation.AddEntityIDs(ids...)
	return spu
}

// AddEntities adds the "entities" edges to the Entity entity.
func (spu *StoragePolicyUpdate) AddEntities(e ...*Entity) *StoragePolicyUpdate {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return spu.AddEntityIDs(ids...)
}

// SetNode sets the "node" edge to the Node entity.
func (spu *StoragePolicyUpdate) SetNode(n *Node) *StoragePolicyUpdate {
	return spu.SetNodeID(n.ID)
}

// Mutation returns the StoragePolicyMutation object of the builder.
func (spu *StoragePolicyUpdate) Mutation() *StoragePolicyMutation {
	return spu.mutation
}

// ClearGroups clears all "groups" edges to the Group entity.
func (spu *StoragePolicyUpdate) ClearGroups() *StoragePolicyUpdate {
	spu.mutation.ClearGroups()
	return spu
}

// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (spu *StoragePolicyUpdate) RemoveGroupIDs(ids ...int) *StoragePolicyUpdate {
	spu.mutation.RemoveGroupIDs(ids...)
	return spu
}

// RemoveGroups removes "groups" edges to Group entities.
func (spu *StoragePolicyUpdate) RemoveGroups(g ...*Group) *StoragePolicyUpdate {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return spu.RemoveGroupIDs(ids...)
}

// ClearFiles clears all "files" edges to the File entity.
func (spu *StoragePolicyUpdate) ClearFiles() *StoragePolicyUpdate {
	spu.mutation.ClearFiles()
	return spu
}

// RemoveFileIDs removes the "files" edge to File entities by IDs.
func (spu *StoragePolicyUpdate) RemoveFileIDs(ids ...int) *StoragePolicyUpdate {
	spu.mutation.RemoveFileIDs(ids...)
	return spu
}

// RemoveFiles removes "files" edges to File entities.
func (spu *StoragePolicyUpdate) RemoveFiles(f ...*File) *StoragePolicyUpdate {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return spu.RemoveFileIDs(ids...)
}

// ClearEntities clears all "entities" edges to the Entity entity.
func (spu *StoragePolicyUpdate) ClearEntities() *StoragePolicyUpdate {
	spu.mutation.ClearEntities()
	return spu
}

// RemoveEntityIDs removes the "entities" edge to Entity entities by IDs.
func (spu *StoragePolicyUpdate) RemoveEntityIDs(ids ...int) *StoragePolicyUpdate {
	spu.mutation.RemoveEntityIDs(ids...)
	return spu
}

// RemoveEntities removes "entities" edges to Entity entities.
func (spu *StoragePolicyUpdate) RemoveEntities(e ...*Entity) *StoragePolicyUpdate {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return spu.RemoveEntityIDs(ids...)
}

// ClearNode clears the "node" edge to the Node entity.
func (spu *StoragePolicyUpdate) ClearNode() *StoragePolicyUpdate {
	spu.mutation.ClearNode()
	return spu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (spu *StoragePolicyUpdate) Save(ctx context.Context) (int, error) {
	if err := spu.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, spu.sqlSave, spu.mutation, spu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (spu *StoragePolicyUpdate) SaveX(ctx context.Context) int {
	affected, err := spu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (spu *StoragePolicyUpdate) Exec(ctx context.Context) error {
	_, err := spu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (spu *StoragePolicyUpdate) ExecX(ctx context.Context) {
	if err := spu.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (spu *StoragePolicyUpdate) defaults() error {
	if _, ok := spu.mutation.UpdatedAt(); !ok {
		if storagepolicy.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized storagepolicy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := storagepolicy.UpdateDefaultUpdatedAt()
		spu.mutation.SetUpdatedAt(v)
	}
	return nil
}

func (spu *StoragePolicyUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(storagepolicy.Table, storagepolicy.Columns, sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt))
	if ps := spu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := spu.mutation.UpdatedAt(); ok {
		_spec.SetField(storagepolicy.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := spu.mutation.DeletedAt(); ok {
		_spec.SetField(storagepolicy.FieldDeletedAt, field.TypeTime, value)
	}
	if spu.mutation.DeletedAtCleared() {
		_spec.ClearField(storagepolicy.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := spu.mutation.Name(); ok {
		_spec.SetField(storagepolicy.FieldName, field.TypeString, value)
	}
	if value, ok := spu.mutation.GetType(); ok {
		_spec.SetField(storagepolicy.FieldType, field.TypeString, value)
	}
	if value, ok := spu.mutation.Server(); ok {
		_spec.SetField(storagepolicy.FieldServer, field.TypeString, value)
	}
	if spu.mutation.ServerCleared() {
		_spec.ClearField(storagepolicy.FieldServer, field.TypeString)
	}
	if value, ok := spu.mutation.BucketName(); ok {
		_spec.SetField(storagepolicy.FieldBucketName, field.TypeString, value)
	}
	if spu.mutation.BucketNameCleared() {
		_spec.ClearField(storagepolicy.FieldBucketName, field.TypeString)
	}
	if value, ok := spu.mutation.IsPrivate(); ok {
		_spec.SetField(storagepolicy.FieldIsPrivate, field.TypeBool, value)
	}
	if spu.mutation.IsPrivateCleared() {
		_spec.ClearField(storagepolicy.FieldIsPrivate, field.TypeBool)
	}
	if value, ok := spu.mutation.AccessKey(); ok {
		_spec.SetField(storagepolicy.FieldAccessKey, field.TypeString, value)
	}
	if spu.mutation.AccessKeyCleared() {
		_spec.ClearField(storagepolicy.FieldAccessKey, field.TypeString)
	}
	if value, ok := spu.mutation.SecretKey(); ok {
		_spec.SetField(storagepolicy.FieldSecretKey, field.TypeString, value)
	}
	if spu.mutation.SecretKeyCleared() {
		_spec.ClearField(storagepolicy.FieldSecretKey, field.TypeString)
	}
	if value, ok := spu.mutation.MaxSize(); ok {
		_spec.SetField(storagepolicy.FieldMaxSize, field.TypeInt64, value)
	}
	if value, ok := spu.mutation.AddedMaxSize(); ok {
		_spec.AddField(storagepolicy.FieldMaxSize, field.TypeInt64, value)
	}
	if spu.mutation.MaxSizeCleared() {
		_spec.ClearField(storagepolicy.FieldMaxSize, field.TypeInt64)
	}
	if value, ok := spu.mutation.DirNameRule(); ok {
		_spec.SetField(storagepolicy.FieldDirNameRule, field.TypeString, value)
	}
	if spu.mutation.DirNameRuleCleared() {
		_spec.ClearField(storagepolicy.FieldDirNameRule, field.TypeString)
	}
	if value, ok := spu.mutation.FileNameRule(); ok {
		_spec.SetField(storagepolicy.FieldFileNameRule, field.TypeString, value)
	}
	if spu.mutation.FileNameRuleCleared() {
		_spec.ClearField(storagepolicy.FieldFileNameRule, field.TypeString)
	}
	if value, ok := spu.mutation.Settings(); ok {
		_spec.SetField(storagepolicy.FieldSettings, field.TypeJSON, value)
	}
	if spu.mutation.SettingsCleared() {
		_spec.ClearField(storagepolicy.FieldSettings, field.TypeJSON)
	}
	if spu.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.GroupsTable,
			Columns: []string{storagepolicy.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !spu.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.GroupsTable,
			Columns: []string{storagepolicy.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.GroupsTable,
			Columns: []string{storagepolicy.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if spu.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.FilesTable,
			Columns: []string{storagepolicy.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.RemovedFilesIDs(); len(nodes) > 0 && !spu.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.FilesTable,
			Columns: []string{storagepolicy.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.FilesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.FilesTable,
			Columns: []string{storagepolicy.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if spu.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.EntitiesTable,
			Columns: []string{storagepolicy.EntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.RemovedEntitiesIDs(); len(nodes) > 0 && !spu.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.EntitiesTable,
			Columns: []string{storagepolicy.EntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.EntitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.EntitiesTable,
			Columns: []string{storagepolicy.EntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if spu.mutation.NodeCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   storagepolicy.NodeTable,
			Columns: []string{storagepolicy.NodeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spu.mutation.NodeIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   storagepolicy.NodeTable,
			Columns: []string{storagepolicy.NodeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, spu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{storagepolicy.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	spu.mutation.done = true
	return n, nil
}

// StoragePolicyUpdateOne is the builder for updating a single StoragePolicy entity.
type StoragePolicyUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *StoragePolicyMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (spuo *StoragePolicyUpdateOne) SetUpdatedAt(t time.Time) *StoragePolicyUpdateOne {
	spuo.mutation.SetUpdatedAt(t)
	return spuo
}

// SetDeletedAt sets the "deleted_at" field.
func (spuo *StoragePolicyUpdateOne) SetDeletedAt(t time.Time) *StoragePolicyUpdateOne {
	spuo.mutation.SetDeletedAt(t)
	return spuo
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableDeletedAt(t *time.Time) *StoragePolicyUpdateOne {
	if t != nil {
		spuo.SetDeletedAt(*t)
	}
	return spuo
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (spuo *StoragePolicyUpdateOne) ClearDeletedAt() *StoragePolicyUpdateOne {
	spuo.mutation.ClearDeletedAt()
	return spuo
}

// SetName sets the "name" field.
func (spuo *StoragePolicyUpdateOne) SetName(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetName(s)
	return spuo
}

// SetNillableName sets the "name" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableName(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetName(*s)
	}
	return spuo
}

// SetType sets the "type" field.
func (spuo *StoragePolicyUpdateOne) SetType(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetType(s)
	return spuo
}

// SetNillableType sets the "type" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableType(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetType(*s)
	}
	return spuo
}

// SetServer sets the "server" field.
func (spuo *StoragePolicyUpdateOne) SetServer(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetServer(s)
	return spuo
}

// SetNillableServer sets the "server" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableServer(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetServer(*s)
	}
	return spuo
}

// ClearServer clears the value of the "server" field.
func (spuo *StoragePolicyUpdateOne) ClearServer() *StoragePolicyUpdateOne {
	spuo.mutation.ClearServer()
	return spuo
}

// SetBucketName sets the "bucket_name" field.
func (spuo *StoragePolicyUpdateOne) SetBucketName(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetBucketName(s)
	return spuo
}

// SetNillableBucketName sets the "bucket_name" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableBucketName(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetBucketName(*s)
	}
	return spuo
}

// ClearBucketName clears the value of the "bucket_name" field.
func (spuo *StoragePolicyUpdateOne) ClearBucketName() *StoragePolicyUpdateOne {
	spuo.mutation.ClearBucketName()
	return spuo
}

// SetIsPrivate sets the "is_private" field.
func (spuo *StoragePolicyUpdateOne) SetIsPrivate(b bool) *StoragePolicyUpdateOne {
	spuo.mutation.SetIsPrivate(b)
	return spuo
}

// SetNillableIsPrivate sets the "is_private" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableIsPrivate(b *bool) *StoragePolicyUpdateOne {
	if b != nil {
		spuo.SetIsPrivate(*b)
	}
	return spuo
}

// ClearIsPrivate clears the value of the "is_private" field.
func (spuo *StoragePolicyUpdateOne) ClearIsPrivate() *StoragePolicyUpdateOne {
	spuo.mutation.ClearIsPrivate()
	return spuo
}

// SetAccessKey sets the "access_key" field.
func (spuo *StoragePolicyUpdateOne) SetAccessKey(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetAccessKey(s)
	return spuo
}

// SetNillableAccessKey sets the "access_key" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableAccessKey(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetAccessKey(*s)
	}
	return spuo
}

// ClearAccessKey clears the value of the "access_key" field.
func (spuo *StoragePolicyUpdateOne) ClearAccessKey() *StoragePolicyUpdateOne {
	spuo.mutation.ClearAccessKey()
	return spuo
}

// SetSecretKey sets the "secret_key" field.
func (spuo *StoragePolicyUpdateOne) SetSecretKey(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetSecretKey(s)
	return spuo
}

// SetNillableSecretKey sets the "secret_key" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableSecretKey(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetSecretKey(*s)
	}
	return spuo
}

// ClearSecretKey clears the value of the "secret_key" field.
func (spuo *StoragePolicyUpdateOne) ClearSecretKey() *StoragePolicyUpdateOne {
	spuo.mutation.ClearSecretKey()
	return spuo
}

// SetMaxSize sets the "max_size" field.
func (spuo *StoragePolicyUpdateOne) SetMaxSize(i int64) *StoragePolicyUpdateOne {
	spuo.mutation.ResetMaxSize()
	spuo.mutation.SetMaxSize(i)
	return spuo
}

// SetNillableMaxSize sets the "max_size" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableMaxSize(i *int64) *StoragePolicyUpdateOne {
	if i != nil {
		spuo.SetMaxSize(*i)
	}
	return spuo
}

// AddMaxSize adds i to the "max_size" field.
func (spuo *StoragePolicyUpdateOne) AddMaxSize(i int64) *StoragePolicyUpdateOne {
	spuo.mutation.AddMaxSize(i)
	return spuo
}

// ClearMaxSize clears the value of the "max_size" field.
func (spuo *StoragePolicyUpdateOne) ClearMaxSize() *StoragePolicyUpdateOne {
	spuo.mutation.ClearMaxSize()
	return spuo
}

// SetDirNameRule sets the "dir_name_rule" field.
func (spuo *StoragePolicyUpdateOne) SetDirNameRule(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetDirNameRule(s)
	return spuo
}

// SetNillableDirNameRule sets the "dir_name_rule" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableDirNameRule(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetDirNameRule(*s)
	}
	return spuo
}

// ClearDirNameRule clears the value of the "dir_name_rule" field.
func (spuo *StoragePolicyUpdateOne) ClearDirNameRule() *StoragePolicyUpdateOne {
	spuo.mutation.ClearDirNameRule()
	return spuo
}

// SetFileNameRule sets the "file_name_rule" field.
func (spuo *StoragePolicyUpdateOne) SetFileNameRule(s string) *StoragePolicyUpdateOne {
	spuo.mutation.SetFileNameRule(s)
	return spuo
}

// SetNillableFileNameRule sets the "file_name_rule" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableFileNameRule(s *string) *StoragePolicyUpdateOne {
	if s != nil {
		spuo.SetFileNameRule(*s)
	}
	return spuo
}

// ClearFileNameRule clears the value of the "file_name_rule" field.
func (spuo *StoragePolicyUpdateOne) ClearFileNameRule() *StoragePolicyUpdateOne {
	spuo.mutation.ClearFileNameRule()
	return spuo
}

// SetSettings sets the "settings" field.
func (spuo *StoragePolicyUpdateOne) SetSettings(ts *types.PolicySetting) *StoragePolicyUpdateOne {
	spuo.mutation.SetSettings(ts)
	return spuo
}

// ClearSettings clears the value of the "settings" field.
func (spuo *StoragePolicyUpdateOne) ClearSettings() *StoragePolicyUpdateOne {
	spuo.mutation.ClearSettings()
	return spuo
}

// SetNodeID sets the "node_id" field.
func (spuo *StoragePolicyUpdateOne) SetNodeID(i int) *StoragePolicyUpdateOne {
	spuo.mutation.SetNodeID(i)
	return spuo
}

// SetNillableNodeID sets the "node_id" field if the given value is not nil.
func (spuo *StoragePolicyUpdateOne) SetNillableNodeID(i *int) *StoragePolicyUpdateOne {
	if i != nil {
		spuo.SetNodeID(*i)
	}
	return spuo
}

// ClearNodeID clears the value of the "node_id" field.
func (spuo *StoragePolicyUpdateOne) ClearNodeID() *StoragePolicyUpdateOne {
	spuo.mutation.ClearNodeID()
	return spuo
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (spuo *StoragePolicyUpdateOne) AddGroupIDs(ids ...int) *StoragePolicyUpdateOne {
	spuo.mutation.AddGroupIDs(ids...)
	return spuo
}

// AddGroups adds the "groups" edges to the Group entity.
func (spuo *StoragePolicyUpdateOne) AddGroups(g ...*Group) *StoragePolicyUpdateOne {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return spuo.AddGroupIDs(ids...)
}

// AddFileIDs adds the "files" edge to the File entity by IDs.
func (spuo *StoragePolicyUpdateOne) AddFileIDs(ids ...int) *StoragePolicyUpdateOne {
	spuo.mutation.AddFileIDs(ids...)
	return spuo
}

// AddFiles adds the "files" edges to the File entity.
func (spuo *StoragePolicyUpdateOne) AddFiles(f ...*File) *StoragePolicyUpdateOne {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return spuo.AddFileIDs(ids...)
}

// AddEntityIDs adds the "entities" edge to the Entity entity by IDs.
func (spuo *StoragePolicyUpdateOne) AddEntityIDs(ids ...int) *StoragePolicyUpdateOne {
	spuo.mutation.AddEntityIDs(ids...)
	return spuo
}

// AddEntities adds the "entities" edges to the Entity entity.
func (spuo *StoragePolicyUpdateOne) AddEntities(e ...*Entity) *StoragePolicyUpdateOne {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return spuo.AddEntityIDs(ids...)
}

// SetNode sets the "node" edge to the Node entity.
func (spuo *StoragePolicyUpdateOne) SetNode(n *Node) *StoragePolicyUpdateOne {
	return spuo.SetNodeID(n.ID)
}

// Mutation returns the StoragePolicyMutation object of the builder.
func (spuo *StoragePolicyUpdateOne) Mutation() *StoragePolicyMutation {
	return spuo.mutation
}

// ClearGroups clears all "groups" edges to the Group entity.
func (spuo *StoragePolicyUpdateOne) ClearGroups() *StoragePolicyUpdateOne {
	spuo.mutation.ClearGroups()
	return spuo
}

// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (spuo *StoragePolicyUpdateOne) RemoveGroupIDs(ids ...int) *StoragePolicyUpdateOne {
	spuo.mutation.RemoveGroupIDs(ids...)
	return spuo
}

// RemoveGroups removes "groups" edges to Group entities.
func (spuo *StoragePolicyUpdateOne) RemoveGroups(g ...*Group) *StoragePolicyUpdateOne {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return spuo.RemoveGroupIDs(ids...)
}

// ClearFiles clears all "files" edges to the File entity.
func (spuo *StoragePolicyUpdateOne) ClearFiles() *StoragePolicyUpdateOne {
	spuo.mutation.ClearFiles()
	return spuo
}

// RemoveFileIDs removes the "files" edge to File entities by IDs.
func (spuo *StoragePolicyUpdateOne) RemoveFileIDs(ids ...int) *StoragePolicyUpdateOne {
	spuo.mutation.RemoveFileIDs(ids...)
	return spuo
}

// RemoveFiles removes "files" edges to File entities.
func (spuo *StoragePolicyUpdateOne) RemoveFiles(f ...*File) *StoragePolicyUpdateOne {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return spuo.RemoveFileIDs(ids...)
}

// ClearEntities clears all "entities" edges to the Entity entity.
func (spuo *StoragePolicyUpdateOne) ClearEntities() *StoragePolicyUpdateOne {
	spuo.mutation.ClearEntities()
	return spuo
}

// RemoveEntityIDs removes the "entities" edge to Entity entities by IDs.
func (spuo *StoragePolicyUpdateOne) RemoveEntityIDs(ids ...int) *StoragePolicyUpdateOne {
	spuo.mutation.RemoveEntityIDs(ids...)
	return spuo
}

// RemoveEntities removes "entities" edges to Entity entities.
func (spuo *StoragePolicyUpdateOne) RemoveEntities(e ...*Entity) *StoragePolicyUpdateOne {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return spuo.RemoveEntityIDs(ids...)
}

// ClearNode clears the "node" edge to the Node entity.
func (spuo *StoragePolicyUpdateOne) ClearNode() *StoragePolicyUpdateOne {
	spuo.mutation.ClearNode()
	return spuo
}

// Where appends a list predicates to the StoragePolicyUpdate builder.
func (spuo *StoragePolicyUpdateOne) Where(ps ...predicate.StoragePolicy) *StoragePolicyUpdateOne {
	spuo.mutation.Where(ps...)
	return spuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (spuo *StoragePolicyUpdateOne) Select(field string, fields ...string) *StoragePolicyUpdateOne {
	spuo.fields = append([]string{field}, fields...)
	return spuo
}

// Save executes the query and returns the updated StoragePolicy entity.
func (spuo *StoragePolicyUpdateOne) Save(ctx context.Context) (*StoragePolicy, error) {
	if err := spuo.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, spuo.sqlSave, spuo.mutation, spuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (spuo *StoragePolicyUpdateOne) SaveX(ctx context.Context) *StoragePolicy {
	node, err := spuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (spuo *StoragePolicyUpdateOne) Exec(ctx context.Context) error {
	_, err := spuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (spuo *StoragePolicyUpdateOne) ExecX(ctx context.Context) {
	if err := spuo.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (spuo *StoragePolicyUpdateOne) defaults() error {
	if _, ok := spuo.mutation.UpdatedAt(); !ok {
		if storagepolicy.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized storagepolicy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := storagepolicy.UpdateDefaultUpdatedAt()
		spuo.mutation.SetUpdatedAt(v)
	}
	return nil
}

func (spuo *StoragePolicyUpdateOne) sqlSave(ctx context.Context) (_node *StoragePolicy, err error) {
	_spec := sqlgraph.NewUpdateSpec(storagepolicy.Table, storagepolicy.Columns, sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt))
	id, ok := spuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "StoragePolicy.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := spuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, storagepolicy.FieldID)
		for _, f := range fields {
			if !storagepolicy.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != storagepolicy.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := spuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := spuo.mutation.UpdatedAt(); ok {
		_spec.SetField(storagepolicy.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := spuo.mutation.DeletedAt(); ok {
		_spec.SetField(storagepolicy.FieldDeletedAt, field.TypeTime, value)
	}
	if spuo.mutation.DeletedAtCleared() {
		_spec.ClearField(storagepolicy.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := spuo.mutation.Name(); ok {
		_spec.SetField(storagepolicy.FieldName, field.TypeString, value)
	}
	if value, ok := spuo.mutation.GetType(); ok {
		_spec.SetField(storagepolicy.FieldType, field.TypeString, value)
	}
	if value, ok := spuo.mutation.Server(); ok {
		_spec.SetField(storagepolicy.FieldServer, field.TypeString, value)
	}
	if spuo.mutation.ServerCleared() {
		_spec.ClearField(storagepolicy.FieldServer, field.TypeString)
	}
	if value, ok := spuo.mutation.BucketName(); ok {
		_spec.SetField(storagepolicy.FieldBucketName, field.TypeString, value)
	}
	if spuo.mutation.BucketNameCleared() {
		_spec.ClearField(storagepolicy.FieldBucketName, field.TypeString)
	}
	if value, ok := spuo.mutation.IsPrivate(); ok {
		_spec.SetField(storagepolicy.FieldIsPrivate, field.TypeBool, value)
	}
	if spuo.mutation.IsPrivateCleared() {
		_spec.ClearField(storagepolicy.FieldIsPrivate, field.TypeBool)
	}
	if value, ok := spuo.mutation.AccessKey(); ok {
		_spec.SetField(storagepolicy.FieldAccessKey, field.TypeString, value)
	}
	if spuo.mutation.AccessKeyCleared() {
		_spec.ClearField(storagepolicy.FieldAccessKey, field.TypeString)
	}
	if value, ok := spuo.mutation.SecretKey(); ok {
		_spec.SetField(storagepolicy.FieldSecretKey, field.TypeString, value)
	}
	if spuo.mutation.SecretKeyCleared() {
		_spec.ClearField(storagepolicy.FieldSecretKey, field.TypeString)
	}
	if value, ok := spuo.mutation.MaxSize(); ok {
		_spec.SetField(storagepolicy.FieldMaxSize, field.TypeInt64, value)
	}
	if value, ok := spuo.mutation.AddedMaxSize(); ok {
		_spec.AddField(storagepolicy.FieldMaxSize, field.TypeInt64, value)
	}
	if spuo.mutation.MaxSizeCleared() {
		_spec.ClearField(storagepolicy.FieldMaxSize, field.TypeInt64)
	}
	if value, ok := spuo.mutation.DirNameRule(); ok {
		_spec.SetField(storagepolicy.FieldDirNameRule, field.TypeString, value)
	}
	if spuo.mutation.DirNameRuleCleared() {
		_spec.ClearField(storagepolicy.FieldDirNameRule, field.TypeString)
	}
	if value, ok := spuo.mutation.FileNameRule(); ok {
		_spec.SetField(storagepolicy.FieldFileNameRule, field.TypeString, value)
	}
	if spuo.mutation.FileNameRuleCleared() {
		_spec.ClearField(storagepolicy.FieldFileNameRule, field.TypeString)
	}
	if value, ok := spuo.mutation.Settings(); ok {
		_spec.SetField(storagepolicy.FieldSettings, field.TypeJSON, value)
	}
	if spuo.mutation.SettingsCleared() {
		_spec.ClearField(storagepolicy.FieldSettings, field.TypeJSON)
	}
	if spuo.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.GroupsTable,
			Columns: []string{storagepolicy.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !spuo.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.GroupsTable,
			Columns: []string{storagepolicy.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.GroupsTable,
			Columns: []string{storagepolicy.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if spuo.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.FilesTable,
			Columns: []string{storagepolicy.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.RemovedFilesIDs(); len(nodes) > 0 && !spuo.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.FilesTable,
			Columns: []string{storagepolicy.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.FilesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.FilesTable,
			Columns: []string{storagepolicy.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if spuo.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.EntitiesTable,
			Columns: []string{storagepolicy.EntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.RemovedEntitiesIDs(); len(nodes) > 0 && !spuo.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.EntitiesTable,
			Columns: []string{storagepolicy.EntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.EntitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   storagepolicy.EntitiesTable,
			Columns: []string{storagepolicy.EntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if spuo.mutation.NodeCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   storagepolicy.NodeTable,
			Columns: []string{storagepolicy.NodeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := spuo.mutation.NodeIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   storagepolicy.NodeTable,
			Columns: []string{storagepolicy.NodeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &StoragePolicy{config: spuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, spuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{storagepolicy.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	spuo.mutation.done = true
	return _node, nil
}
