// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
	"github.com/in-toto/archivista/ent/attestationcollection"
	"github.com/in-toto/archivista/ent/attestationpolicy"
	"github.com/in-toto/archivista/ent/dsse"
	"github.com/in-toto/archivista/ent/predicate"
	"github.com/in-toto/archivista/ent/statement"
	"github.com/in-toto/archivista/ent/subject"
)

// StatementUpdate is the builder for updating Statement entities.
type StatementUpdate struct {
	config
	hooks    []Hook
	mutation *StatementMutation
}

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

// SetPredicate sets the "predicate" field.
func (_u *StatementUpdate) SetPredicate(v string) *StatementUpdate {
	_u.mutation.SetPredicate(v)
	return _u
}

// SetNillablePredicate sets the "predicate" field if the given value is not nil.
func (_u *StatementUpdate) SetNillablePredicate(v *string) *StatementUpdate {
	if v != nil {
		_u.SetPredicate(*v)
	}
	return _u
}

// AddSubjectIDs adds the "subjects" edge to the Subject entity by IDs.
func (_u *StatementUpdate) AddSubjectIDs(ids ...uuid.UUID) *StatementUpdate {
	_u.mutation.AddSubjectIDs(ids...)
	return _u
}

// AddSubjects adds the "subjects" edges to the Subject entity.
func (_u *StatementUpdate) AddSubjects(v ...*Subject) *StatementUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSubjectIDs(ids...)
}

// SetPolicyID sets the "policy" edge to the AttestationPolicy entity by ID.
func (_u *StatementUpdate) SetPolicyID(id uuid.UUID) *StatementUpdate {
	_u.mutation.SetPolicyID(id)
	return _u
}

// SetNillablePolicyID sets the "policy" edge to the AttestationPolicy entity by ID if the given value is not nil.
func (_u *StatementUpdate) SetNillablePolicyID(id *uuid.UUID) *StatementUpdate {
	if id != nil {
		_u = _u.SetPolicyID(*id)
	}
	return _u
}

// SetPolicy sets the "policy" edge to the AttestationPolicy entity.
func (_u *StatementUpdate) SetPolicy(v *AttestationPolicy) *StatementUpdate {
	return _u.SetPolicyID(v.ID)
}

// SetAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID.
func (_u *StatementUpdate) SetAttestationCollectionsID(id uuid.UUID) *StatementUpdate {
	_u.mutation.SetAttestationCollectionsID(id)
	return _u
}

// SetNillableAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID if the given value is not nil.
func (_u *StatementUpdate) SetNillableAttestationCollectionsID(id *uuid.UUID) *StatementUpdate {
	if id != nil {
		_u = _u.SetAttestationCollectionsID(*id)
	}
	return _u
}

// SetAttestationCollections sets the "attestation_collections" edge to the AttestationCollection entity.
func (_u *StatementUpdate) SetAttestationCollections(v *AttestationCollection) *StatementUpdate {
	return _u.SetAttestationCollectionsID(v.ID)
}

// AddDsseIDs adds the "dsse" edge to the Dsse entity by IDs.
func (_u *StatementUpdate) AddDsseIDs(ids ...uuid.UUID) *StatementUpdate {
	_u.mutation.AddDsseIDs(ids...)
	return _u
}

// AddDsse adds the "dsse" edges to the Dsse entity.
func (_u *StatementUpdate) AddDsse(v ...*Dsse) *StatementUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddDsseIDs(ids...)
}

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

// ClearSubjects clears all "subjects" edges to the Subject entity.
func (_u *StatementUpdate) ClearSubjects() *StatementUpdate {
	_u.mutation.ClearSubjects()
	return _u
}

// RemoveSubjectIDs removes the "subjects" edge to Subject entities by IDs.
func (_u *StatementUpdate) RemoveSubjectIDs(ids ...uuid.UUID) *StatementUpdate {
	_u.mutation.RemoveSubjectIDs(ids...)
	return _u
}

// RemoveSubjects removes "subjects" edges to Subject entities.
func (_u *StatementUpdate) RemoveSubjects(v ...*Subject) *StatementUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSubjectIDs(ids...)
}

// ClearPolicy clears the "policy" edge to the AttestationPolicy entity.
func (_u *StatementUpdate) ClearPolicy() *StatementUpdate {
	_u.mutation.ClearPolicy()
	return _u
}

// ClearAttestationCollections clears the "attestation_collections" edge to the AttestationCollection entity.
func (_u *StatementUpdate) ClearAttestationCollections() *StatementUpdate {
	_u.mutation.ClearAttestationCollections()
	return _u
}

// ClearDsse clears all "dsse" edges to the Dsse entity.
func (_u *StatementUpdate) ClearDsse() *StatementUpdate {
	_u.mutation.ClearDsse()
	return _u
}

// RemoveDsseIDs removes the "dsse" edge to Dsse entities by IDs.
func (_u *StatementUpdate) RemoveDsseIDs(ids ...uuid.UUID) *StatementUpdate {
	_u.mutation.RemoveDsseIDs(ids...)
	return _u
}

// RemoveDsse removes "dsse" edges to Dsse entities.
func (_u *StatementUpdate) RemoveDsse(v ...*Dsse) *StatementUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveDsseIDs(ids...)
}

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

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

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

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

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

func (_u *StatementUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(statement.Table, statement.Columns, sqlgraph.NewFieldSpec(statement.FieldID, field.TypeUUID))
	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.Predicate(); ok {
		_spec.SetField(statement.FieldPredicate, field.TypeString, value)
	}
	if _u.mutation.SubjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   statement.SubjectsTable,
			Columns: []string{statement.SubjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSubjectsIDs(); len(nodes) > 0 && !_u.mutation.SubjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   statement.SubjectsTable,
			Columns: []string{statement.SubjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SubjectsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   statement.SubjectsTable,
			Columns: []string{statement.SubjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.PolicyCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.PolicyTable,
			Columns: []string{statement.PolicyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.PolicyIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.PolicyTable,
			Columns: []string{statement.PolicyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.AttestationCollectionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.AttestationCollectionsTable,
			Columns: []string{statement.AttestationCollectionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AttestationCollectionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.AttestationCollectionsTable,
			Columns: []string{statement.AttestationCollectionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.DsseCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   statement.DsseTable,
			Columns: []string{statement.DsseColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedDsseIDs(); len(nodes) > 0 && !_u.mutation.DsseCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   statement.DsseTable,
			Columns: []string{statement.DsseColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   statement.DsseTable,
			Columns: []string{statement.DsseColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{statement.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// StatementUpdateOne is the builder for updating a single Statement entity.
type StatementUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *StatementMutation
}

// SetPredicate sets the "predicate" field.
func (_u *StatementUpdateOne) SetPredicate(v string) *StatementUpdateOne {
	_u.mutation.SetPredicate(v)
	return _u
}

// SetNillablePredicate sets the "predicate" field if the given value is not nil.
func (_u *StatementUpdateOne) SetNillablePredicate(v *string) *StatementUpdateOne {
	if v != nil {
		_u.SetPredicate(*v)
	}
	return _u
}

// AddSubjectIDs adds the "subjects" edge to the Subject entity by IDs.
func (_u *StatementUpdateOne) AddSubjectIDs(ids ...uuid.UUID) *StatementUpdateOne {
	_u.mutation.AddSubjectIDs(ids...)
	return _u
}

// AddSubjects adds the "subjects" edges to the Subject entity.
func (_u *StatementUpdateOne) AddSubjects(v ...*Subject) *StatementUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSubjectIDs(ids...)
}

// SetPolicyID sets the "policy" edge to the AttestationPolicy entity by ID.
func (_u *StatementUpdateOne) SetPolicyID(id uuid.UUID) *StatementUpdateOne {
	_u.mutation.SetPolicyID(id)
	return _u
}

// SetNillablePolicyID sets the "policy" edge to the AttestationPolicy entity by ID if the given value is not nil.
func (_u *StatementUpdateOne) SetNillablePolicyID(id *uuid.UUID) *StatementUpdateOne {
	if id != nil {
		_u = _u.SetPolicyID(*id)
	}
	return _u
}

// SetPolicy sets the "policy" edge to the AttestationPolicy entity.
func (_u *StatementUpdateOne) SetPolicy(v *AttestationPolicy) *StatementUpdateOne {
	return _u.SetPolicyID(v.ID)
}

// SetAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID.
func (_u *StatementUpdateOne) SetAttestationCollectionsID(id uuid.UUID) *StatementUpdateOne {
	_u.mutation.SetAttestationCollectionsID(id)
	return _u
}

// SetNillableAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID if the given value is not nil.
func (_u *StatementUpdateOne) SetNillableAttestationCollectionsID(id *uuid.UUID) *StatementUpdateOne {
	if id != nil {
		_u = _u.SetAttestationCollectionsID(*id)
	}
	return _u
}

// SetAttestationCollections sets the "attestation_collections" edge to the AttestationCollection entity.
func (_u *StatementUpdateOne) SetAttestationCollections(v *AttestationCollection) *StatementUpdateOne {
	return _u.SetAttestationCollectionsID(v.ID)
}

// AddDsseIDs adds the "dsse" edge to the Dsse entity by IDs.
func (_u *StatementUpdateOne) AddDsseIDs(ids ...uuid.UUID) *StatementUpdateOne {
	_u.mutation.AddDsseIDs(ids...)
	return _u
}

// AddDsse adds the "dsse" edges to the Dsse entity.
func (_u *StatementUpdateOne) AddDsse(v ...*Dsse) *StatementUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddDsseIDs(ids...)
}

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

// ClearSubjects clears all "subjects" edges to the Subject entity.
func (_u *StatementUpdateOne) ClearSubjects() *StatementUpdateOne {
	_u.mutation.ClearSubjects()
	return _u
}

// RemoveSubjectIDs removes the "subjects" edge to Subject entities by IDs.
func (_u *StatementUpdateOne) RemoveSubjectIDs(ids ...uuid.UUID) *StatementUpdateOne {
	_u.mutation.RemoveSubjectIDs(ids...)
	return _u
}

// RemoveSubjects removes "subjects" edges to Subject entities.
func (_u *StatementUpdateOne) RemoveSubjects(v ...*Subject) *StatementUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSubjectIDs(ids...)
}

// ClearPolicy clears the "policy" edge to the AttestationPolicy entity.
func (_u *StatementUpdateOne) ClearPolicy() *StatementUpdateOne {
	_u.mutation.ClearPolicy()
	return _u
}

// ClearAttestationCollections clears the "attestation_collections" edge to the AttestationCollection entity.
func (_u *StatementUpdateOne) ClearAttestationCollections() *StatementUpdateOne {
	_u.mutation.ClearAttestationCollections()
	return _u
}

// ClearDsse clears all "dsse" edges to the Dsse entity.
func (_u *StatementUpdateOne) ClearDsse() *StatementUpdateOne {
	_u.mutation.ClearDsse()
	return _u
}

// RemoveDsseIDs removes the "dsse" edge to Dsse entities by IDs.
func (_u *StatementUpdateOne) RemoveDsseIDs(ids ...uuid.UUID) *StatementUpdateOne {
	_u.mutation.RemoveDsseIDs(ids...)
	return _u
}

// RemoveDsse removes "dsse" edges to Dsse entities.
func (_u *StatementUpdateOne) RemoveDsse(v ...*Dsse) *StatementUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveDsseIDs(ids...)
}

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

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

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

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

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

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

func (_u *StatementUpdateOne) sqlSave(ctx context.Context) (_node *Statement, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(statement.Table, statement.Columns, sqlgraph.NewFieldSpec(statement.FieldID, field.TypeUUID))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Statement.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, statement.FieldID)
		for _, f := range fields {
			if !statement.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != statement.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.Predicate(); ok {
		_spec.SetField(statement.FieldPredicate, field.TypeString, value)
	}
	if _u.mutation.SubjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   statement.SubjectsTable,
			Columns: []string{statement.SubjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSubjectsIDs(); len(nodes) > 0 && !_u.mutation.SubjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   statement.SubjectsTable,
			Columns: []string{statement.SubjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SubjectsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   statement.SubjectsTable,
			Columns: []string{statement.SubjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.PolicyCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.PolicyTable,
			Columns: []string{statement.PolicyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.PolicyIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.PolicyTable,
			Columns: []string{statement.PolicyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.AttestationCollectionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.AttestationCollectionsTable,
			Columns: []string{statement.AttestationCollectionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AttestationCollectionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   statement.AttestationCollectionsTable,
			Columns: []string{statement.AttestationCollectionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.DsseCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   statement.DsseTable,
			Columns: []string{statement.DsseColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedDsseIDs(); len(nodes) > 0 && !_u.mutation.DsseCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   statement.DsseTable,
			Columns: []string{statement.DsseColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   statement.DsseTable,
			Columns: []string{statement.DsseColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Statement{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{statement.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
