// 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/anzhiyu-c/anheyu-app/ent/predicate"
	"github.com/anzhiyu-c/anheyu-app/ent/user"
	"github.com/anzhiyu-c/anheyu-app/ent/userinstalledtheme"
)

// UserInstalledThemeUpdate is the builder for updating UserInstalledTheme entities.
type UserInstalledThemeUpdate struct {
	config
	hooks     []Hook
	mutation  *UserInstalledThemeMutation
	modifiers []func(*sql.UpdateBuilder)
}

// Where appends a list predicates to the UserInstalledThemeUpdate builder.
func (_u *UserInstalledThemeUpdate) Where(ps ...predicate.UserInstalledTheme) *UserInstalledThemeUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *UserInstalledThemeUpdate) SetDeletedAt(v time.Time) *UserInstalledThemeUpdate {
	_u.mutation.SetDeletedAt(v)
	return _u
}

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

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

// SetUpdatedAt sets the "updated_at" field.
func (_u *UserInstalledThemeUpdate) SetUpdatedAt(v time.Time) *UserInstalledThemeUpdate {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetUserID sets the "user_id" field.
func (_u *UserInstalledThemeUpdate) SetUserID(v uint) *UserInstalledThemeUpdate {
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *UserInstalledThemeUpdate) SetNillableUserID(v *uint) *UserInstalledThemeUpdate {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// SetThemeName sets the "theme_name" field.
func (_u *UserInstalledThemeUpdate) SetThemeName(v string) *UserInstalledThemeUpdate {
	_u.mutation.SetThemeName(v)
	return _u
}

// SetNillableThemeName sets the "theme_name" field if the given value is not nil.
func (_u *UserInstalledThemeUpdate) SetNillableThemeName(v *string) *UserInstalledThemeUpdate {
	if v != nil {
		_u.SetThemeName(*v)
	}
	return _u
}

// SetThemeMarketID sets the "theme_market_id" field.
func (_u *UserInstalledThemeUpdate) SetThemeMarketID(v int) *UserInstalledThemeUpdate {
	_u.mutation.ResetThemeMarketID()
	_u.mutation.SetThemeMarketID(v)
	return _u
}

// SetNillableThemeMarketID sets the "theme_market_id" field if the given value is not nil.
func (_u *UserInstalledThemeUpdate) SetNillableThemeMarketID(v *int) *UserInstalledThemeUpdate {
	if v != nil {
		_u.SetThemeMarketID(*v)
	}
	return _u
}

// AddThemeMarketID adds value to the "theme_market_id" field.
func (_u *UserInstalledThemeUpdate) AddThemeMarketID(v int) *UserInstalledThemeUpdate {
	_u.mutation.AddThemeMarketID(v)
	return _u
}

// ClearThemeMarketID clears the value of the "theme_market_id" field.
func (_u *UserInstalledThemeUpdate) ClearThemeMarketID() *UserInstalledThemeUpdate {
	_u.mutation.ClearThemeMarketID()
	return _u
}

// SetIsCurrent sets the "is_current" field.
func (_u *UserInstalledThemeUpdate) SetIsCurrent(v bool) *UserInstalledThemeUpdate {
	_u.mutation.SetIsCurrent(v)
	return _u
}

// SetNillableIsCurrent sets the "is_current" field if the given value is not nil.
func (_u *UserInstalledThemeUpdate) SetNillableIsCurrent(v *bool) *UserInstalledThemeUpdate {
	if v != nil {
		_u.SetIsCurrent(*v)
	}
	return _u
}

// SetInstallTime sets the "install_time" field.
func (_u *UserInstalledThemeUpdate) SetInstallTime(v time.Time) *UserInstalledThemeUpdate {
	_u.mutation.SetInstallTime(v)
	return _u
}

// SetNillableInstallTime sets the "install_time" field if the given value is not nil.
func (_u *UserInstalledThemeUpdate) SetNillableInstallTime(v *time.Time) *UserInstalledThemeUpdate {
	if v != nil {
		_u.SetInstallTime(*v)
	}
	return _u
}

// SetUserThemeConfig sets the "user_theme_config" field.
func (_u *UserInstalledThemeUpdate) SetUserThemeConfig(v map[string]interface{}) *UserInstalledThemeUpdate {
	_u.mutation.SetUserThemeConfig(v)
	return _u
}

// ClearUserThemeConfig clears the value of the "user_theme_config" field.
func (_u *UserInstalledThemeUpdate) ClearUserThemeConfig() *UserInstalledThemeUpdate {
	_u.mutation.ClearUserThemeConfig()
	return _u
}

// SetInstalledVersion sets the "installed_version" field.
func (_u *UserInstalledThemeUpdate) SetInstalledVersion(v string) *UserInstalledThemeUpdate {
	_u.mutation.SetInstalledVersion(v)
	return _u
}

// SetNillableInstalledVersion sets the "installed_version" field if the given value is not nil.
func (_u *UserInstalledThemeUpdate) SetNillableInstalledVersion(v *string) *UserInstalledThemeUpdate {
	if v != nil {
		_u.SetInstalledVersion(*v)
	}
	return _u
}

// ClearInstalledVersion clears the value of the "installed_version" field.
func (_u *UserInstalledThemeUpdate) ClearInstalledVersion() *UserInstalledThemeUpdate {
	_u.mutation.ClearInstalledVersion()
	return _u
}

// SetUser sets the "user" edge to the User entity.
func (_u *UserInstalledThemeUpdate) SetUser(v *User) *UserInstalledThemeUpdate {
	return _u.SetUserID(v.ID)
}

// Mutation returns the UserInstalledThemeMutation object of the builder.
func (_u *UserInstalledThemeUpdate) Mutation() *UserInstalledThemeMutation {
	return _u.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (_u *UserInstalledThemeUpdate) ClearUser() *UserInstalledThemeUpdate {
	_u.mutation.ClearUser()
	return _u
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *UserInstalledThemeUpdate) check() error {
	if v, ok := _u.mutation.ThemeName(); ok {
		if err := userinstalledtheme.ThemeNameValidator(v); err != nil {
			return &ValidationError{Name: "theme_name", err: fmt.Errorf(`ent: validator failed for field "UserInstalledTheme.theme_name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.InstalledVersion(); ok {
		if err := userinstalledtheme.InstalledVersionValidator(v); err != nil {
			return &ValidationError{Name: "installed_version", err: fmt.Errorf(`ent: validator failed for field "UserInstalledTheme.installed_version": %w`, err)}
		}
	}
	if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UserInstalledTheme.user"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *UserInstalledThemeUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserInstalledThemeUpdate {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *UserInstalledThemeUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(userinstalledtheme.Table, userinstalledtheme.Columns, sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(userinstalledtheme.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(userinstalledtheme.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(userinstalledtheme.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.ThemeName(); ok {
		_spec.SetField(userinstalledtheme.FieldThemeName, field.TypeString, value)
	}
	if value, ok := _u.mutation.ThemeMarketID(); ok {
		_spec.SetField(userinstalledtheme.FieldThemeMarketID, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedThemeMarketID(); ok {
		_spec.AddField(userinstalledtheme.FieldThemeMarketID, field.TypeInt, value)
	}
	if _u.mutation.ThemeMarketIDCleared() {
		_spec.ClearField(userinstalledtheme.FieldThemeMarketID, field.TypeInt)
	}
	if value, ok := _u.mutation.IsCurrent(); ok {
		_spec.SetField(userinstalledtheme.FieldIsCurrent, field.TypeBool, value)
	}
	if value, ok := _u.mutation.InstallTime(); ok {
		_spec.SetField(userinstalledtheme.FieldInstallTime, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UserThemeConfig(); ok {
		_spec.SetField(userinstalledtheme.FieldUserThemeConfig, field.TypeJSON, value)
	}
	if _u.mutation.UserThemeConfigCleared() {
		_spec.ClearField(userinstalledtheme.FieldUserThemeConfig, field.TypeJSON)
	}
	if value, ok := _u.mutation.InstalledVersion(); ok {
		_spec.SetField(userinstalledtheme.FieldInstalledVersion, field.TypeString, value)
	}
	if _u.mutation.InstalledVersionCleared() {
		_spec.ClearField(userinstalledtheme.FieldInstalledVersion, field.TypeString)
	}
	if _u.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   userinstalledtheme.UserTable,
			Columns: []string{userinstalledtheme.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   userinstalledtheme.UserTable,
			Columns: []string{userinstalledtheme.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{userinstalledtheme.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// UserInstalledThemeUpdateOne is the builder for updating a single UserInstalledTheme entity.
type UserInstalledThemeUpdateOne struct {
	config
	fields    []string
	hooks     []Hook
	mutation  *UserInstalledThemeMutation
	modifiers []func(*sql.UpdateBuilder)
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *UserInstalledThemeUpdateOne) SetDeletedAt(v time.Time) *UserInstalledThemeUpdateOne {
	_u.mutation.SetDeletedAt(v)
	return _u
}

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

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

// SetUpdatedAt sets the "updated_at" field.
func (_u *UserInstalledThemeUpdateOne) SetUpdatedAt(v time.Time) *UserInstalledThemeUpdateOne {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetUserID sets the "user_id" field.
func (_u *UserInstalledThemeUpdateOne) SetUserID(v uint) *UserInstalledThemeUpdateOne {
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *UserInstalledThemeUpdateOne) SetNillableUserID(v *uint) *UserInstalledThemeUpdateOne {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// SetThemeName sets the "theme_name" field.
func (_u *UserInstalledThemeUpdateOne) SetThemeName(v string) *UserInstalledThemeUpdateOne {
	_u.mutation.SetThemeName(v)
	return _u
}

// SetNillableThemeName sets the "theme_name" field if the given value is not nil.
func (_u *UserInstalledThemeUpdateOne) SetNillableThemeName(v *string) *UserInstalledThemeUpdateOne {
	if v != nil {
		_u.SetThemeName(*v)
	}
	return _u
}

// SetThemeMarketID sets the "theme_market_id" field.
func (_u *UserInstalledThemeUpdateOne) SetThemeMarketID(v int) *UserInstalledThemeUpdateOne {
	_u.mutation.ResetThemeMarketID()
	_u.mutation.SetThemeMarketID(v)
	return _u
}

// SetNillableThemeMarketID sets the "theme_market_id" field if the given value is not nil.
func (_u *UserInstalledThemeUpdateOne) SetNillableThemeMarketID(v *int) *UserInstalledThemeUpdateOne {
	if v != nil {
		_u.SetThemeMarketID(*v)
	}
	return _u
}

// AddThemeMarketID adds value to the "theme_market_id" field.
func (_u *UserInstalledThemeUpdateOne) AddThemeMarketID(v int) *UserInstalledThemeUpdateOne {
	_u.mutation.AddThemeMarketID(v)
	return _u
}

// ClearThemeMarketID clears the value of the "theme_market_id" field.
func (_u *UserInstalledThemeUpdateOne) ClearThemeMarketID() *UserInstalledThemeUpdateOne {
	_u.mutation.ClearThemeMarketID()
	return _u
}

// SetIsCurrent sets the "is_current" field.
func (_u *UserInstalledThemeUpdateOne) SetIsCurrent(v bool) *UserInstalledThemeUpdateOne {
	_u.mutation.SetIsCurrent(v)
	return _u
}

// SetNillableIsCurrent sets the "is_current" field if the given value is not nil.
func (_u *UserInstalledThemeUpdateOne) SetNillableIsCurrent(v *bool) *UserInstalledThemeUpdateOne {
	if v != nil {
		_u.SetIsCurrent(*v)
	}
	return _u
}

// SetInstallTime sets the "install_time" field.
func (_u *UserInstalledThemeUpdateOne) SetInstallTime(v time.Time) *UserInstalledThemeUpdateOne {
	_u.mutation.SetInstallTime(v)
	return _u
}

// SetNillableInstallTime sets the "install_time" field if the given value is not nil.
func (_u *UserInstalledThemeUpdateOne) SetNillableInstallTime(v *time.Time) *UserInstalledThemeUpdateOne {
	if v != nil {
		_u.SetInstallTime(*v)
	}
	return _u
}

// SetUserThemeConfig sets the "user_theme_config" field.
func (_u *UserInstalledThemeUpdateOne) SetUserThemeConfig(v map[string]interface{}) *UserInstalledThemeUpdateOne {
	_u.mutation.SetUserThemeConfig(v)
	return _u
}

// ClearUserThemeConfig clears the value of the "user_theme_config" field.
func (_u *UserInstalledThemeUpdateOne) ClearUserThemeConfig() *UserInstalledThemeUpdateOne {
	_u.mutation.ClearUserThemeConfig()
	return _u
}

// SetInstalledVersion sets the "installed_version" field.
func (_u *UserInstalledThemeUpdateOne) SetInstalledVersion(v string) *UserInstalledThemeUpdateOne {
	_u.mutation.SetInstalledVersion(v)
	return _u
}

// SetNillableInstalledVersion sets the "installed_version" field if the given value is not nil.
func (_u *UserInstalledThemeUpdateOne) SetNillableInstalledVersion(v *string) *UserInstalledThemeUpdateOne {
	if v != nil {
		_u.SetInstalledVersion(*v)
	}
	return _u
}

// ClearInstalledVersion clears the value of the "installed_version" field.
func (_u *UserInstalledThemeUpdateOne) ClearInstalledVersion() *UserInstalledThemeUpdateOne {
	_u.mutation.ClearInstalledVersion()
	return _u
}

// SetUser sets the "user" edge to the User entity.
func (_u *UserInstalledThemeUpdateOne) SetUser(v *User) *UserInstalledThemeUpdateOne {
	return _u.SetUserID(v.ID)
}

// Mutation returns the UserInstalledThemeMutation object of the builder.
func (_u *UserInstalledThemeUpdateOne) Mutation() *UserInstalledThemeMutation {
	return _u.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (_u *UserInstalledThemeUpdateOne) ClearUser() *UserInstalledThemeUpdateOne {
	_u.mutation.ClearUser()
	return _u
}

// Where appends a list predicates to the UserInstalledThemeUpdate builder.
func (_u *UserInstalledThemeUpdateOne) Where(ps ...predicate.UserInstalledTheme) *UserInstalledThemeUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

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

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *UserInstalledThemeUpdateOne) check() error {
	if v, ok := _u.mutation.ThemeName(); ok {
		if err := userinstalledtheme.ThemeNameValidator(v); err != nil {
			return &ValidationError{Name: "theme_name", err: fmt.Errorf(`ent: validator failed for field "UserInstalledTheme.theme_name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.InstalledVersion(); ok {
		if err := userinstalledtheme.InstalledVersionValidator(v); err != nil {
			return &ValidationError{Name: "installed_version", err: fmt.Errorf(`ent: validator failed for field "UserInstalledTheme.installed_version": %w`, err)}
		}
	}
	if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UserInstalledTheme.user"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *UserInstalledThemeUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserInstalledThemeUpdateOne {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *UserInstalledThemeUpdateOne) sqlSave(ctx context.Context) (_node *UserInstalledTheme, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(userinstalledtheme.Table, userinstalledtheme.Columns, sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserInstalledTheme.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, userinstalledtheme.FieldID)
		for _, f := range fields {
			if !userinstalledtheme.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != userinstalledtheme.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(userinstalledtheme.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(userinstalledtheme.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(userinstalledtheme.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.ThemeName(); ok {
		_spec.SetField(userinstalledtheme.FieldThemeName, field.TypeString, value)
	}
	if value, ok := _u.mutation.ThemeMarketID(); ok {
		_spec.SetField(userinstalledtheme.FieldThemeMarketID, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedThemeMarketID(); ok {
		_spec.AddField(userinstalledtheme.FieldThemeMarketID, field.TypeInt, value)
	}
	if _u.mutation.ThemeMarketIDCleared() {
		_spec.ClearField(userinstalledtheme.FieldThemeMarketID, field.TypeInt)
	}
	if value, ok := _u.mutation.IsCurrent(); ok {
		_spec.SetField(userinstalledtheme.FieldIsCurrent, field.TypeBool, value)
	}
	if value, ok := _u.mutation.InstallTime(); ok {
		_spec.SetField(userinstalledtheme.FieldInstallTime, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UserThemeConfig(); ok {
		_spec.SetField(userinstalledtheme.FieldUserThemeConfig, field.TypeJSON, value)
	}
	if _u.mutation.UserThemeConfigCleared() {
		_spec.ClearField(userinstalledtheme.FieldUserThemeConfig, field.TypeJSON)
	}
	if value, ok := _u.mutation.InstalledVersion(); ok {
		_spec.SetField(userinstalledtheme.FieldInstalledVersion, field.TypeString, value)
	}
	if _u.mutation.InstalledVersionCleared() {
		_spec.ClearField(userinstalledtheme.FieldInstalledVersion, field.TypeString)
	}
	if _u.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   userinstalledtheme.UserTable,
			Columns: []string{userinstalledtheme.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   userinstalledtheme.UserTable,
			Columns: []string{userinstalledtheme.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	_node = &UserInstalledTheme{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{userinstalledtheme.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
