// 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/AvengeMedia/dankcalendar/core/ent/account"
	"github.com/AvengeMedia/dankcalendar/core/ent/calendar"
	"github.com/AvengeMedia/dankcalendar/core/ent/predicate"
	"github.com/AvengeMedia/dankcalendar/core/ent/secret"
)

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

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

// SetDisplayName sets the "display_name" field.
func (_u *AccountUpdate) SetDisplayName(v string) *AccountUpdate {
	_u.mutation.SetDisplayName(v)
	return _u
}

// SetNillableDisplayName sets the "display_name" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableDisplayName(v *string) *AccountUpdate {
	if v != nil {
		_u.SetDisplayName(*v)
	}
	return _u
}

// SetSettings sets the "settings" field.
func (_u *AccountUpdate) SetSettings(v map[string]interface{}) *AccountUpdate {
	_u.mutation.SetSettings(v)
	return _u
}

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

// SetNeedsReauth sets the "needs_reauth" field.
func (_u *AccountUpdate) SetNeedsReauth(v bool) *AccountUpdate {
	_u.mutation.SetNeedsReauth(v)
	return _u
}

// SetNillableNeedsReauth sets the "needs_reauth" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableNeedsReauth(v *bool) *AccountUpdate {
	if v != nil {
		_u.SetNeedsReauth(*v)
	}
	return _u
}

// SetAuthError sets the "auth_error" field.
func (_u *AccountUpdate) SetAuthError(v string) *AccountUpdate {
	_u.mutation.SetAuthError(v)
	return _u
}

// SetNillableAuthError sets the "auth_error" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableAuthError(v *string) *AccountUpdate {
	if v != nil {
		_u.SetAuthError(*v)
	}
	return _u
}

// ClearAuthError clears the value of the "auth_error" field.
func (_u *AccountUpdate) ClearAuthError() *AccountUpdate {
	_u.mutation.ClearAuthError()
	return _u
}

// SetSyncNotice sets the "sync_notice" field.
func (_u *AccountUpdate) SetSyncNotice(v string) *AccountUpdate {
	_u.mutation.SetSyncNotice(v)
	return _u
}

// SetNillableSyncNotice sets the "sync_notice" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableSyncNotice(v *string) *AccountUpdate {
	if v != nil {
		_u.SetSyncNotice(*v)
	}
	return _u
}

// ClearSyncNotice clears the value of the "sync_notice" field.
func (_u *AccountUpdate) ClearSyncNotice() *AccountUpdate {
	_u.mutation.ClearSyncNotice()
	return _u
}

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

// AddCalendarIDs adds the "calendars" edge to the Calendar entity by IDs.
func (_u *AccountUpdate) AddCalendarIDs(ids ...string) *AccountUpdate {
	_u.mutation.AddCalendarIDs(ids...)
	return _u
}

// AddCalendars adds the "calendars" edges to the Calendar entity.
func (_u *AccountUpdate) AddCalendars(v ...*Calendar) *AccountUpdate {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddCalendarIDs(ids...)
}

// AddSecretIDs adds the "secrets" edge to the Secret entity by IDs.
func (_u *AccountUpdate) AddSecretIDs(ids ...string) *AccountUpdate {
	_u.mutation.AddSecretIDs(ids...)
	return _u
}

// AddSecrets adds the "secrets" edges to the Secret entity.
func (_u *AccountUpdate) AddSecrets(v ...*Secret) *AccountUpdate {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSecretIDs(ids...)
}

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

// ClearCalendars clears all "calendars" edges to the Calendar entity.
func (_u *AccountUpdate) ClearCalendars() *AccountUpdate {
	_u.mutation.ClearCalendars()
	return _u
}

// RemoveCalendarIDs removes the "calendars" edge to Calendar entities by IDs.
func (_u *AccountUpdate) RemoveCalendarIDs(ids ...string) *AccountUpdate {
	_u.mutation.RemoveCalendarIDs(ids...)
	return _u
}

// RemoveCalendars removes "calendars" edges to Calendar entities.
func (_u *AccountUpdate) RemoveCalendars(v ...*Calendar) *AccountUpdate {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveCalendarIDs(ids...)
}

// ClearSecrets clears all "secrets" edges to the Secret entity.
func (_u *AccountUpdate) ClearSecrets() *AccountUpdate {
	_u.mutation.ClearSecrets()
	return _u
}

// RemoveSecretIDs removes the "secrets" edge to Secret entities by IDs.
func (_u *AccountUpdate) RemoveSecretIDs(ids ...string) *AccountUpdate {
	_u.mutation.RemoveSecretIDs(ids...)
	return _u
}

// RemoveSecrets removes "secrets" edges to Secret entities.
func (_u *AccountUpdate) RemoveSecrets(v ...*Secret) *AccountUpdate {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSecretIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *AccountUpdate) Save(ctx context.Context) (int, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *AccountUpdate) 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 *AccountUpdate) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := account.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *AccountUpdate) check() error {
	if v, ok := _u.mutation.DisplayName(); ok {
		if err := account.DisplayNameValidator(v); err != nil {
			return &ValidationError{Name: "display_name", err: fmt.Errorf(`ent: validator failed for field "Account.display_name": %w`, err)}
		}
	}
	return nil
}

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

func (_u *AccountUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeString))
	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.DisplayName(); ok {
		_spec.SetField(account.FieldDisplayName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Settings(); ok {
		_spec.SetField(account.FieldSettings, field.TypeJSON, value)
	}
	if _u.mutation.SettingsCleared() {
		_spec.ClearField(account.FieldSettings, field.TypeJSON)
	}
	if value, ok := _u.mutation.NeedsReauth(); ok {
		_spec.SetField(account.FieldNeedsReauth, field.TypeBool, value)
	}
	if value, ok := _u.mutation.AuthError(); ok {
		_spec.SetField(account.FieldAuthError, field.TypeString, value)
	}
	if _u.mutation.AuthErrorCleared() {
		_spec.ClearField(account.FieldAuthError, field.TypeString)
	}
	if value, ok := _u.mutation.SyncNotice(); ok {
		_spec.SetField(account.FieldSyncNotice, field.TypeString, value)
	}
	if _u.mutation.SyncNoticeCleared() {
		_spec.ClearField(account.FieldSyncNotice, field.TypeString)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.CalendarsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.CalendarsTable,
			Columns: []string{account.CalendarsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedCalendarsIDs(); len(nodes) > 0 && !_u.mutation.CalendarsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.CalendarsTable,
			Columns: []string{account.CalendarsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.CalendarsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.CalendarsTable,
			Columns: []string{account.CalendarsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.SecretsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.SecretsTable,
			Columns: []string{account.SecretsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(secret.FieldID, field.TypeString),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSecretsIDs(); len(nodes) > 0 && !_u.mutation.SecretsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.SecretsTable,
			Columns: []string{account.SecretsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(secret.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SecretsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.SecretsTable,
			Columns: []string{account.SecretsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(secret.FieldID, field.TypeString),
			},
		}
		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{account.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

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

// SetDisplayName sets the "display_name" field.
func (_u *AccountUpdateOne) SetDisplayName(v string) *AccountUpdateOne {
	_u.mutation.SetDisplayName(v)
	return _u
}

// SetNillableDisplayName sets the "display_name" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableDisplayName(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetDisplayName(*v)
	}
	return _u
}

// SetSettings sets the "settings" field.
func (_u *AccountUpdateOne) SetSettings(v map[string]interface{}) *AccountUpdateOne {
	_u.mutation.SetSettings(v)
	return _u
}

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

// SetNeedsReauth sets the "needs_reauth" field.
func (_u *AccountUpdateOne) SetNeedsReauth(v bool) *AccountUpdateOne {
	_u.mutation.SetNeedsReauth(v)
	return _u
}

// SetNillableNeedsReauth sets the "needs_reauth" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableNeedsReauth(v *bool) *AccountUpdateOne {
	if v != nil {
		_u.SetNeedsReauth(*v)
	}
	return _u
}

// SetAuthError sets the "auth_error" field.
func (_u *AccountUpdateOne) SetAuthError(v string) *AccountUpdateOne {
	_u.mutation.SetAuthError(v)
	return _u
}

// SetNillableAuthError sets the "auth_error" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableAuthError(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetAuthError(*v)
	}
	return _u
}

// ClearAuthError clears the value of the "auth_error" field.
func (_u *AccountUpdateOne) ClearAuthError() *AccountUpdateOne {
	_u.mutation.ClearAuthError()
	return _u
}

// SetSyncNotice sets the "sync_notice" field.
func (_u *AccountUpdateOne) SetSyncNotice(v string) *AccountUpdateOne {
	_u.mutation.SetSyncNotice(v)
	return _u
}

// SetNillableSyncNotice sets the "sync_notice" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableSyncNotice(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetSyncNotice(*v)
	}
	return _u
}

// ClearSyncNotice clears the value of the "sync_notice" field.
func (_u *AccountUpdateOne) ClearSyncNotice() *AccountUpdateOne {
	_u.mutation.ClearSyncNotice()
	return _u
}

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

// AddCalendarIDs adds the "calendars" edge to the Calendar entity by IDs.
func (_u *AccountUpdateOne) AddCalendarIDs(ids ...string) *AccountUpdateOne {
	_u.mutation.AddCalendarIDs(ids...)
	return _u
}

// AddCalendars adds the "calendars" edges to the Calendar entity.
func (_u *AccountUpdateOne) AddCalendars(v ...*Calendar) *AccountUpdateOne {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddCalendarIDs(ids...)
}

// AddSecretIDs adds the "secrets" edge to the Secret entity by IDs.
func (_u *AccountUpdateOne) AddSecretIDs(ids ...string) *AccountUpdateOne {
	_u.mutation.AddSecretIDs(ids...)
	return _u
}

// AddSecrets adds the "secrets" edges to the Secret entity.
func (_u *AccountUpdateOne) AddSecrets(v ...*Secret) *AccountUpdateOne {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSecretIDs(ids...)
}

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

// ClearCalendars clears all "calendars" edges to the Calendar entity.
func (_u *AccountUpdateOne) ClearCalendars() *AccountUpdateOne {
	_u.mutation.ClearCalendars()
	return _u
}

// RemoveCalendarIDs removes the "calendars" edge to Calendar entities by IDs.
func (_u *AccountUpdateOne) RemoveCalendarIDs(ids ...string) *AccountUpdateOne {
	_u.mutation.RemoveCalendarIDs(ids...)
	return _u
}

// RemoveCalendars removes "calendars" edges to Calendar entities.
func (_u *AccountUpdateOne) RemoveCalendars(v ...*Calendar) *AccountUpdateOne {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveCalendarIDs(ids...)
}

// ClearSecrets clears all "secrets" edges to the Secret entity.
func (_u *AccountUpdateOne) ClearSecrets() *AccountUpdateOne {
	_u.mutation.ClearSecrets()
	return _u
}

// RemoveSecretIDs removes the "secrets" edge to Secret entities by IDs.
func (_u *AccountUpdateOne) RemoveSecretIDs(ids ...string) *AccountUpdateOne {
	_u.mutation.RemoveSecretIDs(ids...)
	return _u
}

// RemoveSecrets removes "secrets" edges to Secret entities.
func (_u *AccountUpdateOne) RemoveSecrets(v ...*Secret) *AccountUpdateOne {
	ids := make([]string, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSecretIDs(ids...)
}

// Where appends a list predicates to the AccountUpdate builder.
func (_u *AccountUpdateOne) Where(ps ...predicate.Account) *AccountUpdateOne {
	_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 *AccountUpdateOne) Select(field string, fields ...string) *AccountUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

// Save executes the query and returns the updated Account entity.
func (_u *AccountUpdateOne) Save(ctx context.Context) (*Account, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *AccountUpdateOne) 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 *AccountUpdateOne) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := account.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *AccountUpdateOne) check() error {
	if v, ok := _u.mutation.DisplayName(); ok {
		if err := account.DisplayNameValidator(v); err != nil {
			return &ValidationError{Name: "display_name", err: fmt.Errorf(`ent: validator failed for field "Account.display_name": %w`, err)}
		}
	}
	return nil
}

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

func (_u *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeString))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.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, account.FieldID)
		for _, f := range fields {
			if !account.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != account.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.DisplayName(); ok {
		_spec.SetField(account.FieldDisplayName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Settings(); ok {
		_spec.SetField(account.FieldSettings, field.TypeJSON, value)
	}
	if _u.mutation.SettingsCleared() {
		_spec.ClearField(account.FieldSettings, field.TypeJSON)
	}
	if value, ok := _u.mutation.NeedsReauth(); ok {
		_spec.SetField(account.FieldNeedsReauth, field.TypeBool, value)
	}
	if value, ok := _u.mutation.AuthError(); ok {
		_spec.SetField(account.FieldAuthError, field.TypeString, value)
	}
	if _u.mutation.AuthErrorCleared() {
		_spec.ClearField(account.FieldAuthError, field.TypeString)
	}
	if value, ok := _u.mutation.SyncNotice(); ok {
		_spec.SetField(account.FieldSyncNotice, field.TypeString, value)
	}
	if _u.mutation.SyncNoticeCleared() {
		_spec.ClearField(account.FieldSyncNotice, field.TypeString)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.CalendarsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.CalendarsTable,
			Columns: []string{account.CalendarsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedCalendarsIDs(); len(nodes) > 0 && !_u.mutation.CalendarsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.CalendarsTable,
			Columns: []string{account.CalendarsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.CalendarsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.CalendarsTable,
			Columns: []string{account.CalendarsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.SecretsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.SecretsTable,
			Columns: []string{account.SecretsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(secret.FieldID, field.TypeString),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSecretsIDs(); len(nodes) > 0 && !_u.mutation.SecretsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.SecretsTable,
			Columns: []string{account.SecretsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(secret.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SecretsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.SecretsTable,
			Columns: []string{account.SecretsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(secret.FieldID, field.TypeString),
			},
		}
		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 = &Account{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{account.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
