// 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/file"
	"github.com/cloudreve/Cloudreve/v4/ent/predicate"
	"github.com/cloudreve/Cloudreve/v4/ent/share"
	"github.com/cloudreve/Cloudreve/v4/ent/user"
	"github.com/cloudreve/Cloudreve/v4/inventory/types"
)

// ShareUpdate is the builder for updating Share entities.
type ShareUpdate struct {
	config
	hooks    []Hook
	mutation *ShareMutation
}

// Where appends a list predicates to the ShareUpdate builder.
func (su *ShareUpdate) Where(ps ...predicate.Share) *ShareUpdate {
	su.mutation.Where(ps...)
	return su
}

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

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

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

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

// SetPassword sets the "password" field.
func (su *ShareUpdate) SetPassword(s string) *ShareUpdate {
	su.mutation.SetPassword(s)
	return su
}

// SetNillablePassword sets the "password" field if the given value is not nil.
func (su *ShareUpdate) SetNillablePassword(s *string) *ShareUpdate {
	if s != nil {
		su.SetPassword(*s)
	}
	return su
}

// ClearPassword clears the value of the "password" field.
func (su *ShareUpdate) ClearPassword() *ShareUpdate {
	su.mutation.ClearPassword()
	return su
}

// SetViews sets the "views" field.
func (su *ShareUpdate) SetViews(i int) *ShareUpdate {
	su.mutation.ResetViews()
	su.mutation.SetViews(i)
	return su
}

// SetNillableViews sets the "views" field if the given value is not nil.
func (su *ShareUpdate) SetNillableViews(i *int) *ShareUpdate {
	if i != nil {
		su.SetViews(*i)
	}
	return su
}

// AddViews adds i to the "views" field.
func (su *ShareUpdate) AddViews(i int) *ShareUpdate {
	su.mutation.AddViews(i)
	return su
}

// SetDownloads sets the "downloads" field.
func (su *ShareUpdate) SetDownloads(i int) *ShareUpdate {
	su.mutation.ResetDownloads()
	su.mutation.SetDownloads(i)
	return su
}

// SetNillableDownloads sets the "downloads" field if the given value is not nil.
func (su *ShareUpdate) SetNillableDownloads(i *int) *ShareUpdate {
	if i != nil {
		su.SetDownloads(*i)
	}
	return su
}

// AddDownloads adds i to the "downloads" field.
func (su *ShareUpdate) AddDownloads(i int) *ShareUpdate {
	su.mutation.AddDownloads(i)
	return su
}

// SetExpires sets the "expires" field.
func (su *ShareUpdate) SetExpires(t time.Time) *ShareUpdate {
	su.mutation.SetExpires(t)
	return su
}

// SetNillableExpires sets the "expires" field if the given value is not nil.
func (su *ShareUpdate) SetNillableExpires(t *time.Time) *ShareUpdate {
	if t != nil {
		su.SetExpires(*t)
	}
	return su
}

// ClearExpires clears the value of the "expires" field.
func (su *ShareUpdate) ClearExpires() *ShareUpdate {
	su.mutation.ClearExpires()
	return su
}

// SetRemainDownloads sets the "remain_downloads" field.
func (su *ShareUpdate) SetRemainDownloads(i int) *ShareUpdate {
	su.mutation.ResetRemainDownloads()
	su.mutation.SetRemainDownloads(i)
	return su
}

// SetNillableRemainDownloads sets the "remain_downloads" field if the given value is not nil.
func (su *ShareUpdate) SetNillableRemainDownloads(i *int) *ShareUpdate {
	if i != nil {
		su.SetRemainDownloads(*i)
	}
	return su
}

// AddRemainDownloads adds i to the "remain_downloads" field.
func (su *ShareUpdate) AddRemainDownloads(i int) *ShareUpdate {
	su.mutation.AddRemainDownloads(i)
	return su
}

// ClearRemainDownloads clears the value of the "remain_downloads" field.
func (su *ShareUpdate) ClearRemainDownloads() *ShareUpdate {
	su.mutation.ClearRemainDownloads()
	return su
}

// SetProps sets the "props" field.
func (su *ShareUpdate) SetProps(tp *types.ShareProps) *ShareUpdate {
	su.mutation.SetProps(tp)
	return su
}

// ClearProps clears the value of the "props" field.
func (su *ShareUpdate) ClearProps() *ShareUpdate {
	su.mutation.ClearProps()
	return su
}

// SetUserID sets the "user" edge to the User entity by ID.
func (su *ShareUpdate) SetUserID(id int) *ShareUpdate {
	su.mutation.SetUserID(id)
	return su
}

// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (su *ShareUpdate) SetNillableUserID(id *int) *ShareUpdate {
	if id != nil {
		su = su.SetUserID(*id)
	}
	return su
}

// SetUser sets the "user" edge to the User entity.
func (su *ShareUpdate) SetUser(u *User) *ShareUpdate {
	return su.SetUserID(u.ID)
}

// SetFileID sets the "file" edge to the File entity by ID.
func (su *ShareUpdate) SetFileID(id int) *ShareUpdate {
	su.mutation.SetFileID(id)
	return su
}

// SetNillableFileID sets the "file" edge to the File entity by ID if the given value is not nil.
func (su *ShareUpdate) SetNillableFileID(id *int) *ShareUpdate {
	if id != nil {
		su = su.SetFileID(*id)
	}
	return su
}

// SetFile sets the "file" edge to the File entity.
func (su *ShareUpdate) SetFile(f *File) *ShareUpdate {
	return su.SetFileID(f.ID)
}

// Mutation returns the ShareMutation object of the builder.
func (su *ShareUpdate) Mutation() *ShareMutation {
	return su.mutation
}

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

// ClearFile clears the "file" edge to the File entity.
func (su *ShareUpdate) ClearFile() *ShareUpdate {
	su.mutation.ClearFile()
	return su
}

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

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

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

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

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

func (su *ShareUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(share.Table, share.Columns, sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt))
	if ps := su.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := su.mutation.UpdatedAt(); ok {
		_spec.SetField(share.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := su.mutation.DeletedAt(); ok {
		_spec.SetField(share.FieldDeletedAt, field.TypeTime, value)
	}
	if su.mutation.DeletedAtCleared() {
		_spec.ClearField(share.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := su.mutation.Password(); ok {
		_spec.SetField(share.FieldPassword, field.TypeString, value)
	}
	if su.mutation.PasswordCleared() {
		_spec.ClearField(share.FieldPassword, field.TypeString)
	}
	if value, ok := su.mutation.Views(); ok {
		_spec.SetField(share.FieldViews, field.TypeInt, value)
	}
	if value, ok := su.mutation.AddedViews(); ok {
		_spec.AddField(share.FieldViews, field.TypeInt, value)
	}
	if value, ok := su.mutation.Downloads(); ok {
		_spec.SetField(share.FieldDownloads, field.TypeInt, value)
	}
	if value, ok := su.mutation.AddedDownloads(); ok {
		_spec.AddField(share.FieldDownloads, field.TypeInt, value)
	}
	if value, ok := su.mutation.Expires(); ok {
		_spec.SetField(share.FieldExpires, field.TypeTime, value)
	}
	if su.mutation.ExpiresCleared() {
		_spec.ClearField(share.FieldExpires, field.TypeTime)
	}
	if value, ok := su.mutation.RemainDownloads(); ok {
		_spec.SetField(share.FieldRemainDownloads, field.TypeInt, value)
	}
	if value, ok := su.mutation.AddedRemainDownloads(); ok {
		_spec.AddField(share.FieldRemainDownloads, field.TypeInt, value)
	}
	if su.mutation.RemainDownloadsCleared() {
		_spec.ClearField(share.FieldRemainDownloads, field.TypeInt)
	}
	if value, ok := su.mutation.Props(); ok {
		_spec.SetField(share.FieldProps, field.TypeJSON, value)
	}
	if su.mutation.PropsCleared() {
		_spec.ClearField(share.FieldProps, field.TypeJSON)
	}
	if su.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.UserTable,
			Columns: []string{share.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := su.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.UserTable,
			Columns: []string{share.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if su.mutation.FileCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.FileTable,
			Columns: []string{share.FileColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := su.mutation.FileIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.FileTable,
			Columns: []string{share.FileColumn},
			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 n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{share.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	su.mutation.done = true
	return n, nil
}

// ShareUpdateOne is the builder for updating a single Share entity.
type ShareUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ShareMutation
}

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

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

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

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

// SetPassword sets the "password" field.
func (suo *ShareUpdateOne) SetPassword(s string) *ShareUpdateOne {
	suo.mutation.SetPassword(s)
	return suo
}

// SetNillablePassword sets the "password" field if the given value is not nil.
func (suo *ShareUpdateOne) SetNillablePassword(s *string) *ShareUpdateOne {
	if s != nil {
		suo.SetPassword(*s)
	}
	return suo
}

// ClearPassword clears the value of the "password" field.
func (suo *ShareUpdateOne) ClearPassword() *ShareUpdateOne {
	suo.mutation.ClearPassword()
	return suo
}

// SetViews sets the "views" field.
func (suo *ShareUpdateOne) SetViews(i int) *ShareUpdateOne {
	suo.mutation.ResetViews()
	suo.mutation.SetViews(i)
	return suo
}

// SetNillableViews sets the "views" field if the given value is not nil.
func (suo *ShareUpdateOne) SetNillableViews(i *int) *ShareUpdateOne {
	if i != nil {
		suo.SetViews(*i)
	}
	return suo
}

// AddViews adds i to the "views" field.
func (suo *ShareUpdateOne) AddViews(i int) *ShareUpdateOne {
	suo.mutation.AddViews(i)
	return suo
}

// SetDownloads sets the "downloads" field.
func (suo *ShareUpdateOne) SetDownloads(i int) *ShareUpdateOne {
	suo.mutation.ResetDownloads()
	suo.mutation.SetDownloads(i)
	return suo
}

// SetNillableDownloads sets the "downloads" field if the given value is not nil.
func (suo *ShareUpdateOne) SetNillableDownloads(i *int) *ShareUpdateOne {
	if i != nil {
		suo.SetDownloads(*i)
	}
	return suo
}

// AddDownloads adds i to the "downloads" field.
func (suo *ShareUpdateOne) AddDownloads(i int) *ShareUpdateOne {
	suo.mutation.AddDownloads(i)
	return suo
}

// SetExpires sets the "expires" field.
func (suo *ShareUpdateOne) SetExpires(t time.Time) *ShareUpdateOne {
	suo.mutation.SetExpires(t)
	return suo
}

// SetNillableExpires sets the "expires" field if the given value is not nil.
func (suo *ShareUpdateOne) SetNillableExpires(t *time.Time) *ShareUpdateOne {
	if t != nil {
		suo.SetExpires(*t)
	}
	return suo
}

// ClearExpires clears the value of the "expires" field.
func (suo *ShareUpdateOne) ClearExpires() *ShareUpdateOne {
	suo.mutation.ClearExpires()
	return suo
}

// SetRemainDownloads sets the "remain_downloads" field.
func (suo *ShareUpdateOne) SetRemainDownloads(i int) *ShareUpdateOne {
	suo.mutation.ResetRemainDownloads()
	suo.mutation.SetRemainDownloads(i)
	return suo
}

// SetNillableRemainDownloads sets the "remain_downloads" field if the given value is not nil.
func (suo *ShareUpdateOne) SetNillableRemainDownloads(i *int) *ShareUpdateOne {
	if i != nil {
		suo.SetRemainDownloads(*i)
	}
	return suo
}

// AddRemainDownloads adds i to the "remain_downloads" field.
func (suo *ShareUpdateOne) AddRemainDownloads(i int) *ShareUpdateOne {
	suo.mutation.AddRemainDownloads(i)
	return suo
}

// ClearRemainDownloads clears the value of the "remain_downloads" field.
func (suo *ShareUpdateOne) ClearRemainDownloads() *ShareUpdateOne {
	suo.mutation.ClearRemainDownloads()
	return suo
}

// SetProps sets the "props" field.
func (suo *ShareUpdateOne) SetProps(tp *types.ShareProps) *ShareUpdateOne {
	suo.mutation.SetProps(tp)
	return suo
}

// ClearProps clears the value of the "props" field.
func (suo *ShareUpdateOne) ClearProps() *ShareUpdateOne {
	suo.mutation.ClearProps()
	return suo
}

// SetUserID sets the "user" edge to the User entity by ID.
func (suo *ShareUpdateOne) SetUserID(id int) *ShareUpdateOne {
	suo.mutation.SetUserID(id)
	return suo
}

// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (suo *ShareUpdateOne) SetNillableUserID(id *int) *ShareUpdateOne {
	if id != nil {
		suo = suo.SetUserID(*id)
	}
	return suo
}

// SetUser sets the "user" edge to the User entity.
func (suo *ShareUpdateOne) SetUser(u *User) *ShareUpdateOne {
	return suo.SetUserID(u.ID)
}

// SetFileID sets the "file" edge to the File entity by ID.
func (suo *ShareUpdateOne) SetFileID(id int) *ShareUpdateOne {
	suo.mutation.SetFileID(id)
	return suo
}

// SetNillableFileID sets the "file" edge to the File entity by ID if the given value is not nil.
func (suo *ShareUpdateOne) SetNillableFileID(id *int) *ShareUpdateOne {
	if id != nil {
		suo = suo.SetFileID(*id)
	}
	return suo
}

// SetFile sets the "file" edge to the File entity.
func (suo *ShareUpdateOne) SetFile(f *File) *ShareUpdateOne {
	return suo.SetFileID(f.ID)
}

// Mutation returns the ShareMutation object of the builder.
func (suo *ShareUpdateOne) Mutation() *ShareMutation {
	return suo.mutation
}

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

// ClearFile clears the "file" edge to the File entity.
func (suo *ShareUpdateOne) ClearFile() *ShareUpdateOne {
	suo.mutation.ClearFile()
	return suo
}

// Where appends a list predicates to the ShareUpdate builder.
func (suo *ShareUpdateOne) Where(ps ...predicate.Share) *ShareUpdateOne {
	suo.mutation.Where(ps...)
	return suo
}

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

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

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

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

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

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

func (suo *ShareUpdateOne) sqlSave(ctx context.Context) (_node *Share, err error) {
	_spec := sqlgraph.NewUpdateSpec(share.Table, share.Columns, sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt))
	id, ok := suo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Share.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := suo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, share.FieldID)
		for _, f := range fields {
			if !share.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != share.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := suo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := suo.mutation.UpdatedAt(); ok {
		_spec.SetField(share.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := suo.mutation.DeletedAt(); ok {
		_spec.SetField(share.FieldDeletedAt, field.TypeTime, value)
	}
	if suo.mutation.DeletedAtCleared() {
		_spec.ClearField(share.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := suo.mutation.Password(); ok {
		_spec.SetField(share.FieldPassword, field.TypeString, value)
	}
	if suo.mutation.PasswordCleared() {
		_spec.ClearField(share.FieldPassword, field.TypeString)
	}
	if value, ok := suo.mutation.Views(); ok {
		_spec.SetField(share.FieldViews, field.TypeInt, value)
	}
	if value, ok := suo.mutation.AddedViews(); ok {
		_spec.AddField(share.FieldViews, field.TypeInt, value)
	}
	if value, ok := suo.mutation.Downloads(); ok {
		_spec.SetField(share.FieldDownloads, field.TypeInt, value)
	}
	if value, ok := suo.mutation.AddedDownloads(); ok {
		_spec.AddField(share.FieldDownloads, field.TypeInt, value)
	}
	if value, ok := suo.mutation.Expires(); ok {
		_spec.SetField(share.FieldExpires, field.TypeTime, value)
	}
	if suo.mutation.ExpiresCleared() {
		_spec.ClearField(share.FieldExpires, field.TypeTime)
	}
	if value, ok := suo.mutation.RemainDownloads(); ok {
		_spec.SetField(share.FieldRemainDownloads, field.TypeInt, value)
	}
	if value, ok := suo.mutation.AddedRemainDownloads(); ok {
		_spec.AddField(share.FieldRemainDownloads, field.TypeInt, value)
	}
	if suo.mutation.RemainDownloadsCleared() {
		_spec.ClearField(share.FieldRemainDownloads, field.TypeInt)
	}
	if value, ok := suo.mutation.Props(); ok {
		_spec.SetField(share.FieldProps, field.TypeJSON, value)
	}
	if suo.mutation.PropsCleared() {
		_spec.ClearField(share.FieldProps, field.TypeJSON)
	}
	if suo.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.UserTable,
			Columns: []string{share.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := suo.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.UserTable,
			Columns: []string{share.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if suo.mutation.FileCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.FileTable,
			Columns: []string{share.FileColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := suo.mutation.FileIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   share.FileTable,
			Columns: []string{share.FileColumn},
			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)
	}
	_node = &Share{config: suo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{share.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	suo.mutation.done = true
	return _node, nil
}
