// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/label"
	"wechat-api/ent/labelrelationship"
	"wechat-api/ent/predicate"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// LabelUpdate is the builder for updating Label entities.
type LabelUpdate struct {
	config
	hooks    []Hook
	mutation *LabelMutation
}

// Where appends a list predicates to the LabelUpdate builder.
func (lu *LabelUpdate) Where(ps ...predicate.Label) *LabelUpdate {
	lu.mutation.Where(ps...)
	return lu
}

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

// SetStatus sets the "status" field.
func (lu *LabelUpdate) SetStatus(u uint8) *LabelUpdate {
	lu.mutation.ResetStatus()
	lu.mutation.SetStatus(u)
	return lu
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (lu *LabelUpdate) SetNillableStatus(u *uint8) *LabelUpdate {
	if u != nil {
		lu.SetStatus(*u)
	}
	return lu
}

// AddStatus adds u to the "status" field.
func (lu *LabelUpdate) AddStatus(u int8) *LabelUpdate {
	lu.mutation.AddStatus(u)
	return lu
}

// ClearStatus clears the value of the "status" field.
func (lu *LabelUpdate) ClearStatus() *LabelUpdate {
	lu.mutation.ClearStatus()
	return lu
}

// SetType sets the "type" field.
func (lu *LabelUpdate) SetType(i int) *LabelUpdate {
	lu.mutation.ResetType()
	lu.mutation.SetType(i)
	return lu
}

// SetNillableType sets the "type" field if the given value is not nil.
func (lu *LabelUpdate) SetNillableType(i *int) *LabelUpdate {
	if i != nil {
		lu.SetType(*i)
	}
	return lu
}

// AddType adds i to the "type" field.
func (lu *LabelUpdate) AddType(i int) *LabelUpdate {
	lu.mutation.AddType(i)
	return lu
}

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

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

// SetFrom sets the "from" field.
func (lu *LabelUpdate) SetFrom(i int) *LabelUpdate {
	lu.mutation.ResetFrom()
	lu.mutation.SetFrom(i)
	return lu
}

// SetNillableFrom sets the "from" field if the given value is not nil.
func (lu *LabelUpdate) SetNillableFrom(i *int) *LabelUpdate {
	if i != nil {
		lu.SetFrom(*i)
	}
	return lu
}

// AddFrom adds i to the "from" field.
func (lu *LabelUpdate) AddFrom(i int) *LabelUpdate {
	lu.mutation.AddFrom(i)
	return lu
}

// SetMode sets the "mode" field.
func (lu *LabelUpdate) SetMode(i int) *LabelUpdate {
	lu.mutation.ResetMode()
	lu.mutation.SetMode(i)
	return lu
}

// SetNillableMode sets the "mode" field if the given value is not nil.
func (lu *LabelUpdate) SetNillableMode(i *int) *LabelUpdate {
	if i != nil {
		lu.SetMode(*i)
	}
	return lu
}

// AddMode adds i to the "mode" field.
func (lu *LabelUpdate) AddMode(i int) *LabelUpdate {
	lu.mutation.AddMode(i)
	return lu
}

// SetConditions sets the "conditions" field.
func (lu *LabelUpdate) SetConditions(s string) *LabelUpdate {
	lu.mutation.SetConditions(s)
	return lu
}

// SetNillableConditions sets the "conditions" field if the given value is not nil.
func (lu *LabelUpdate) SetNillableConditions(s *string) *LabelUpdate {
	if s != nil {
		lu.SetConditions(*s)
	}
	return lu
}

// ClearConditions clears the value of the "conditions" field.
func (lu *LabelUpdate) ClearConditions() *LabelUpdate {
	lu.mutation.ClearConditions()
	return lu
}

// SetOrganizationID sets the "organization_id" field.
func (lu *LabelUpdate) SetOrganizationID(u uint64) *LabelUpdate {
	lu.mutation.ResetOrganizationID()
	lu.mutation.SetOrganizationID(u)
	return lu
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (lu *LabelUpdate) SetNillableOrganizationID(u *uint64) *LabelUpdate {
	if u != nil {
		lu.SetOrganizationID(*u)
	}
	return lu
}

// AddOrganizationID adds u to the "organization_id" field.
func (lu *LabelUpdate) AddOrganizationID(u int64) *LabelUpdate {
	lu.mutation.AddOrganizationID(u)
	return lu
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (lu *LabelUpdate) ClearOrganizationID() *LabelUpdate {
	lu.mutation.ClearOrganizationID()
	return lu
}

// AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
func (lu *LabelUpdate) AddLabelRelationshipIDs(ids ...uint64) *LabelUpdate {
	lu.mutation.AddLabelRelationshipIDs(ids...)
	return lu
}

// AddLabelRelationships adds the "label_relationships" edges to the LabelRelationship entity.
func (lu *LabelUpdate) AddLabelRelationships(l ...*LabelRelationship) *LabelUpdate {
	ids := make([]uint64, len(l))
	for i := range l {
		ids[i] = l[i].ID
	}
	return lu.AddLabelRelationshipIDs(ids...)
}

// Mutation returns the LabelMutation object of the builder.
func (lu *LabelUpdate) Mutation() *LabelMutation {
	return lu.mutation
}

// ClearLabelRelationships clears all "label_relationships" edges to the LabelRelationship entity.
func (lu *LabelUpdate) ClearLabelRelationships() *LabelUpdate {
	lu.mutation.ClearLabelRelationships()
	return lu
}

// RemoveLabelRelationshipIDs removes the "label_relationships" edge to LabelRelationship entities by IDs.
func (lu *LabelUpdate) RemoveLabelRelationshipIDs(ids ...uint64) *LabelUpdate {
	lu.mutation.RemoveLabelRelationshipIDs(ids...)
	return lu
}

// RemoveLabelRelationships removes "label_relationships" edges to LabelRelationship entities.
func (lu *LabelUpdate) RemoveLabelRelationships(l ...*LabelRelationship) *LabelUpdate {
	ids := make([]uint64, len(l))
	for i := range l {
		ids[i] = l[i].ID
	}
	return lu.RemoveLabelRelationshipIDs(ids...)
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (lu *LabelUpdate) defaults() {
	if _, ok := lu.mutation.UpdatedAt(); !ok {
		v := label.UpdateDefaultUpdatedAt()
		lu.mutation.SetUpdatedAt(v)
	}
}

func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUint64))
	if ps := lu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := lu.mutation.UpdatedAt(); ok {
		_spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := lu.mutation.Status(); ok {
		_spec.SetField(label.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := lu.mutation.AddedStatus(); ok {
		_spec.AddField(label.FieldStatus, field.TypeUint8, value)
	}
	if lu.mutation.StatusCleared() {
		_spec.ClearField(label.FieldStatus, field.TypeUint8)
	}
	if value, ok := lu.mutation.GetType(); ok {
		_spec.SetField(label.FieldType, field.TypeInt, value)
	}
	if value, ok := lu.mutation.AddedType(); ok {
		_spec.AddField(label.FieldType, field.TypeInt, value)
	}
	if value, ok := lu.mutation.Name(); ok {
		_spec.SetField(label.FieldName, field.TypeString, value)
	}
	if value, ok := lu.mutation.From(); ok {
		_spec.SetField(label.FieldFrom, field.TypeInt, value)
	}
	if value, ok := lu.mutation.AddedFrom(); ok {
		_spec.AddField(label.FieldFrom, field.TypeInt, value)
	}
	if value, ok := lu.mutation.Mode(); ok {
		_spec.SetField(label.FieldMode, field.TypeInt, value)
	}
	if value, ok := lu.mutation.AddedMode(); ok {
		_spec.AddField(label.FieldMode, field.TypeInt, value)
	}
	if value, ok := lu.mutation.Conditions(); ok {
		_spec.SetField(label.FieldConditions, field.TypeString, value)
	}
	if lu.mutation.ConditionsCleared() {
		_spec.ClearField(label.FieldConditions, field.TypeString)
	}
	if value, ok := lu.mutation.OrganizationID(); ok {
		_spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := lu.mutation.AddedOrganizationID(); ok {
		_spec.AddField(label.FieldOrganizationID, field.TypeUint64, value)
	}
	if lu.mutation.OrganizationIDCleared() {
		_spec.ClearField(label.FieldOrganizationID, field.TypeUint64)
	}
	if lu.mutation.LabelRelationshipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   label.LabelRelationshipsTable,
			Columns: []string{label.LabelRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := lu.mutation.RemovedLabelRelationshipsIDs(); len(nodes) > 0 && !lu.mutation.LabelRelationshipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   label.LabelRelationshipsTable,
			Columns: []string{label.LabelRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := lu.mutation.LabelRelationshipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   label.LabelRelationshipsTable,
			Columns: []string{label.LabelRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		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, lu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{label.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	lu.mutation.done = true
	return n, nil
}

// LabelUpdateOne is the builder for updating a single Label entity.
type LabelUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *LabelMutation
}

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

// SetStatus sets the "status" field.
func (luo *LabelUpdateOne) SetStatus(u uint8) *LabelUpdateOne {
	luo.mutation.ResetStatus()
	luo.mutation.SetStatus(u)
	return luo
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (luo *LabelUpdateOne) SetNillableStatus(u *uint8) *LabelUpdateOne {
	if u != nil {
		luo.SetStatus(*u)
	}
	return luo
}

// AddStatus adds u to the "status" field.
func (luo *LabelUpdateOne) AddStatus(u int8) *LabelUpdateOne {
	luo.mutation.AddStatus(u)
	return luo
}

// ClearStatus clears the value of the "status" field.
func (luo *LabelUpdateOne) ClearStatus() *LabelUpdateOne {
	luo.mutation.ClearStatus()
	return luo
}

// SetType sets the "type" field.
func (luo *LabelUpdateOne) SetType(i int) *LabelUpdateOne {
	luo.mutation.ResetType()
	luo.mutation.SetType(i)
	return luo
}

// SetNillableType sets the "type" field if the given value is not nil.
func (luo *LabelUpdateOne) SetNillableType(i *int) *LabelUpdateOne {
	if i != nil {
		luo.SetType(*i)
	}
	return luo
}

// AddType adds i to the "type" field.
func (luo *LabelUpdateOne) AddType(i int) *LabelUpdateOne {
	luo.mutation.AddType(i)
	return luo
}

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

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

// SetFrom sets the "from" field.
func (luo *LabelUpdateOne) SetFrom(i int) *LabelUpdateOne {
	luo.mutation.ResetFrom()
	luo.mutation.SetFrom(i)
	return luo
}

// SetNillableFrom sets the "from" field if the given value is not nil.
func (luo *LabelUpdateOne) SetNillableFrom(i *int) *LabelUpdateOne {
	if i != nil {
		luo.SetFrom(*i)
	}
	return luo
}

// AddFrom adds i to the "from" field.
func (luo *LabelUpdateOne) AddFrom(i int) *LabelUpdateOne {
	luo.mutation.AddFrom(i)
	return luo
}

// SetMode sets the "mode" field.
func (luo *LabelUpdateOne) SetMode(i int) *LabelUpdateOne {
	luo.mutation.ResetMode()
	luo.mutation.SetMode(i)
	return luo
}

// SetNillableMode sets the "mode" field if the given value is not nil.
func (luo *LabelUpdateOne) SetNillableMode(i *int) *LabelUpdateOne {
	if i != nil {
		luo.SetMode(*i)
	}
	return luo
}

// AddMode adds i to the "mode" field.
func (luo *LabelUpdateOne) AddMode(i int) *LabelUpdateOne {
	luo.mutation.AddMode(i)
	return luo
}

// SetConditions sets the "conditions" field.
func (luo *LabelUpdateOne) SetConditions(s string) *LabelUpdateOne {
	luo.mutation.SetConditions(s)
	return luo
}

// SetNillableConditions sets the "conditions" field if the given value is not nil.
func (luo *LabelUpdateOne) SetNillableConditions(s *string) *LabelUpdateOne {
	if s != nil {
		luo.SetConditions(*s)
	}
	return luo
}

// ClearConditions clears the value of the "conditions" field.
func (luo *LabelUpdateOne) ClearConditions() *LabelUpdateOne {
	luo.mutation.ClearConditions()
	return luo
}

// SetOrganizationID sets the "organization_id" field.
func (luo *LabelUpdateOne) SetOrganizationID(u uint64) *LabelUpdateOne {
	luo.mutation.ResetOrganizationID()
	luo.mutation.SetOrganizationID(u)
	return luo
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (luo *LabelUpdateOne) SetNillableOrganizationID(u *uint64) *LabelUpdateOne {
	if u != nil {
		luo.SetOrganizationID(*u)
	}
	return luo
}

// AddOrganizationID adds u to the "organization_id" field.
func (luo *LabelUpdateOne) AddOrganizationID(u int64) *LabelUpdateOne {
	luo.mutation.AddOrganizationID(u)
	return luo
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (luo *LabelUpdateOne) ClearOrganizationID() *LabelUpdateOne {
	luo.mutation.ClearOrganizationID()
	return luo
}

// AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
func (luo *LabelUpdateOne) AddLabelRelationshipIDs(ids ...uint64) *LabelUpdateOne {
	luo.mutation.AddLabelRelationshipIDs(ids...)
	return luo
}

// AddLabelRelationships adds the "label_relationships" edges to the LabelRelationship entity.
func (luo *LabelUpdateOne) AddLabelRelationships(l ...*LabelRelationship) *LabelUpdateOne {
	ids := make([]uint64, len(l))
	for i := range l {
		ids[i] = l[i].ID
	}
	return luo.AddLabelRelationshipIDs(ids...)
}

// Mutation returns the LabelMutation object of the builder.
func (luo *LabelUpdateOne) Mutation() *LabelMutation {
	return luo.mutation
}

// ClearLabelRelationships clears all "label_relationships" edges to the LabelRelationship entity.
func (luo *LabelUpdateOne) ClearLabelRelationships() *LabelUpdateOne {
	luo.mutation.ClearLabelRelationships()
	return luo
}

// RemoveLabelRelationshipIDs removes the "label_relationships" edge to LabelRelationship entities by IDs.
func (luo *LabelUpdateOne) RemoveLabelRelationshipIDs(ids ...uint64) *LabelUpdateOne {
	luo.mutation.RemoveLabelRelationshipIDs(ids...)
	return luo
}

// RemoveLabelRelationships removes "label_relationships" edges to LabelRelationship entities.
func (luo *LabelUpdateOne) RemoveLabelRelationships(l ...*LabelRelationship) *LabelUpdateOne {
	ids := make([]uint64, len(l))
	for i := range l {
		ids[i] = l[i].ID
	}
	return luo.RemoveLabelRelationshipIDs(ids...)
}

// Where appends a list predicates to the LabelUpdate builder.
func (luo *LabelUpdateOne) Where(ps ...predicate.Label) *LabelUpdateOne {
	luo.mutation.Where(ps...)
	return luo
}

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

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

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

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

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

// defaults sets the default values of the builder before save.
func (luo *LabelUpdateOne) defaults() {
	if _, ok := luo.mutation.UpdatedAt(); !ok {
		v := label.UpdateDefaultUpdatedAt()
		luo.mutation.SetUpdatedAt(v)
	}
}

func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) {
	_spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUint64))
	id, ok := luo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Label.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := luo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, label.FieldID)
		for _, f := range fields {
			if !label.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != label.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := luo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := luo.mutation.UpdatedAt(); ok {
		_spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := luo.mutation.Status(); ok {
		_spec.SetField(label.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := luo.mutation.AddedStatus(); ok {
		_spec.AddField(label.FieldStatus, field.TypeUint8, value)
	}
	if luo.mutation.StatusCleared() {
		_spec.ClearField(label.FieldStatus, field.TypeUint8)
	}
	if value, ok := luo.mutation.GetType(); ok {
		_spec.SetField(label.FieldType, field.TypeInt, value)
	}
	if value, ok := luo.mutation.AddedType(); ok {
		_spec.AddField(label.FieldType, field.TypeInt, value)
	}
	if value, ok := luo.mutation.Name(); ok {
		_spec.SetField(label.FieldName, field.TypeString, value)
	}
	if value, ok := luo.mutation.From(); ok {
		_spec.SetField(label.FieldFrom, field.TypeInt, value)
	}
	if value, ok := luo.mutation.AddedFrom(); ok {
		_spec.AddField(label.FieldFrom, field.TypeInt, value)
	}
	if value, ok := luo.mutation.Mode(); ok {
		_spec.SetField(label.FieldMode, field.TypeInt, value)
	}
	if value, ok := luo.mutation.AddedMode(); ok {
		_spec.AddField(label.FieldMode, field.TypeInt, value)
	}
	if value, ok := luo.mutation.Conditions(); ok {
		_spec.SetField(label.FieldConditions, field.TypeString, value)
	}
	if luo.mutation.ConditionsCleared() {
		_spec.ClearField(label.FieldConditions, field.TypeString)
	}
	if value, ok := luo.mutation.OrganizationID(); ok {
		_spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := luo.mutation.AddedOrganizationID(); ok {
		_spec.AddField(label.FieldOrganizationID, field.TypeUint64, value)
	}
	if luo.mutation.OrganizationIDCleared() {
		_spec.ClearField(label.FieldOrganizationID, field.TypeUint64)
	}
	if luo.mutation.LabelRelationshipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   label.LabelRelationshipsTable,
			Columns: []string{label.LabelRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := luo.mutation.RemovedLabelRelationshipsIDs(); len(nodes) > 0 && !luo.mutation.LabelRelationshipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   label.LabelRelationshipsTable,
			Columns: []string{label.LabelRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := luo.mutation.LabelRelationshipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   label.LabelRelationshipsTable,
			Columns: []string{label.LabelRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Label{config: luo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, luo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{label.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	luo.mutation.done = true
	return _node, nil
}