// 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/chainloop-dev/chainloop/app/controlplane/pkg/authz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/orginvitation"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/predicate"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/user"
	"github.com/google/uuid"
)

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

// Where appends a list predicates to the OrgInvitationUpdate builder.
func (oiu *OrgInvitationUpdate) Where(ps ...predicate.OrgInvitation) *OrgInvitationUpdate {
	oiu.mutation.Where(ps...)
	return oiu
}

// SetStatus sets the "status" field.
func (oiu *OrgInvitationUpdate) SetStatus(bis biz.OrgInvitationStatus) *OrgInvitationUpdate {
	oiu.mutation.SetStatus(bis)
	return oiu
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (oiu *OrgInvitationUpdate) SetNillableStatus(bis *biz.OrgInvitationStatus) *OrgInvitationUpdate {
	if bis != nil {
		oiu.SetStatus(*bis)
	}
	return oiu
}

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

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

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

// SetOrganizationID sets the "organization_id" field.
func (oiu *OrgInvitationUpdate) SetOrganizationID(u uuid.UUID) *OrgInvitationUpdate {
	oiu.mutation.SetOrganizationID(u)
	return oiu
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (oiu *OrgInvitationUpdate) SetNillableOrganizationID(u *uuid.UUID) *OrgInvitationUpdate {
	if u != nil {
		oiu.SetOrganizationID(*u)
	}
	return oiu
}

// SetSenderID sets the "sender_id" field.
func (oiu *OrgInvitationUpdate) SetSenderID(u uuid.UUID) *OrgInvitationUpdate {
	oiu.mutation.SetSenderID(u)
	return oiu
}

// SetNillableSenderID sets the "sender_id" field if the given value is not nil.
func (oiu *OrgInvitationUpdate) SetNillableSenderID(u *uuid.UUID) *OrgInvitationUpdate {
	if u != nil {
		oiu.SetSenderID(*u)
	}
	return oiu
}

// SetRole sets the "role" field.
func (oiu *OrgInvitationUpdate) SetRole(a authz.Role) *OrgInvitationUpdate {
	oiu.mutation.SetRole(a)
	return oiu
}

// SetNillableRole sets the "role" field if the given value is not nil.
func (oiu *OrgInvitationUpdate) SetNillableRole(a *authz.Role) *OrgInvitationUpdate {
	if a != nil {
		oiu.SetRole(*a)
	}
	return oiu
}

// ClearRole clears the value of the "role" field.
func (oiu *OrgInvitationUpdate) ClearRole() *OrgInvitationUpdate {
	oiu.mutation.ClearRole()
	return oiu
}

// SetContext sets the "context" field.
func (oiu *OrgInvitationUpdate) SetContext(bic biz.OrgInvitationContext) *OrgInvitationUpdate {
	oiu.mutation.SetContext(bic)
	return oiu
}

// SetNillableContext sets the "context" field if the given value is not nil.
func (oiu *OrgInvitationUpdate) SetNillableContext(bic *biz.OrgInvitationContext) *OrgInvitationUpdate {
	if bic != nil {
		oiu.SetContext(*bic)
	}
	return oiu
}

// ClearContext clears the value of the "context" field.
func (oiu *OrgInvitationUpdate) ClearContext() *OrgInvitationUpdate {
	oiu.mutation.ClearContext()
	return oiu
}

// SetOrganization sets the "organization" edge to the Organization entity.
func (oiu *OrgInvitationUpdate) SetOrganization(o *Organization) *OrgInvitationUpdate {
	return oiu.SetOrganizationID(o.ID)
}

// SetSender sets the "sender" edge to the User entity.
func (oiu *OrgInvitationUpdate) SetSender(u *User) *OrgInvitationUpdate {
	return oiu.SetSenderID(u.ID)
}

// Mutation returns the OrgInvitationMutation object of the builder.
func (oiu *OrgInvitationUpdate) Mutation() *OrgInvitationMutation {
	return oiu.mutation
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (oiu *OrgInvitationUpdate) ClearOrganization() *OrgInvitationUpdate {
	oiu.mutation.ClearOrganization()
	return oiu
}

// ClearSender clears the "sender" edge to the User entity.
func (oiu *OrgInvitationUpdate) ClearSender() *OrgInvitationUpdate {
	oiu.mutation.ClearSender()
	return oiu
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (oiu *OrgInvitationUpdate) check() error {
	if v, ok := oiu.mutation.Status(); ok {
		if err := orginvitation.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "OrgInvitation.status": %w`, err)}
		}
	}
	if v, ok := oiu.mutation.Role(); ok {
		if err := orginvitation.RoleValidator(v); err != nil {
			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "OrgInvitation.role": %w`, err)}
		}
	}
	if oiu.mutation.OrganizationCleared() && len(oiu.mutation.OrganizationIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "OrgInvitation.organization"`)
	}
	if oiu.mutation.SenderCleared() && len(oiu.mutation.SenderIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "OrgInvitation.sender"`)
	}
	return nil
}

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

func (oiu *OrgInvitationUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := oiu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(orginvitation.Table, orginvitation.Columns, sqlgraph.NewFieldSpec(orginvitation.FieldID, field.TypeUUID))
	if ps := oiu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := oiu.mutation.Status(); ok {
		_spec.SetField(orginvitation.FieldStatus, field.TypeEnum, value)
	}
	if value, ok := oiu.mutation.DeletedAt(); ok {
		_spec.SetField(orginvitation.FieldDeletedAt, field.TypeTime, value)
	}
	if oiu.mutation.DeletedAtCleared() {
		_spec.ClearField(orginvitation.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := oiu.mutation.Role(); ok {
		_spec.SetField(orginvitation.FieldRole, field.TypeEnum, value)
	}
	if oiu.mutation.RoleCleared() {
		_spec.ClearField(orginvitation.FieldRole, field.TypeEnum)
	}
	if value, ok := oiu.mutation.Context(); ok {
		_spec.SetField(orginvitation.FieldContext, field.TypeJSON, value)
	}
	if oiu.mutation.ContextCleared() {
		_spec.ClearField(orginvitation.FieldContext, field.TypeJSON)
	}
	if oiu.mutation.OrganizationCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.OrganizationTable,
			Columns: []string{orginvitation.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := oiu.mutation.OrganizationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.OrganizationTable,
			Columns: []string{orginvitation.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if oiu.mutation.SenderCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.SenderTable,
			Columns: []string{orginvitation.SenderColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := oiu.mutation.SenderIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.SenderTable,
			Columns: []string{orginvitation.SenderColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(oiu.modifiers...)
	if n, err = sqlgraph.UpdateNodes(ctx, oiu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{orginvitation.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	oiu.mutation.done = true
	return n, nil
}

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

// SetStatus sets the "status" field.
func (oiuo *OrgInvitationUpdateOne) SetStatus(bis biz.OrgInvitationStatus) *OrgInvitationUpdateOne {
	oiuo.mutation.SetStatus(bis)
	return oiuo
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (oiuo *OrgInvitationUpdateOne) SetNillableStatus(bis *biz.OrgInvitationStatus) *OrgInvitationUpdateOne {
	if bis != nil {
		oiuo.SetStatus(*bis)
	}
	return oiuo
}

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

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

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

// SetOrganizationID sets the "organization_id" field.
func (oiuo *OrgInvitationUpdateOne) SetOrganizationID(u uuid.UUID) *OrgInvitationUpdateOne {
	oiuo.mutation.SetOrganizationID(u)
	return oiuo
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (oiuo *OrgInvitationUpdateOne) SetNillableOrganizationID(u *uuid.UUID) *OrgInvitationUpdateOne {
	if u != nil {
		oiuo.SetOrganizationID(*u)
	}
	return oiuo
}

// SetSenderID sets the "sender_id" field.
func (oiuo *OrgInvitationUpdateOne) SetSenderID(u uuid.UUID) *OrgInvitationUpdateOne {
	oiuo.mutation.SetSenderID(u)
	return oiuo
}

// SetNillableSenderID sets the "sender_id" field if the given value is not nil.
func (oiuo *OrgInvitationUpdateOne) SetNillableSenderID(u *uuid.UUID) *OrgInvitationUpdateOne {
	if u != nil {
		oiuo.SetSenderID(*u)
	}
	return oiuo
}

// SetRole sets the "role" field.
func (oiuo *OrgInvitationUpdateOne) SetRole(a authz.Role) *OrgInvitationUpdateOne {
	oiuo.mutation.SetRole(a)
	return oiuo
}

// SetNillableRole sets the "role" field if the given value is not nil.
func (oiuo *OrgInvitationUpdateOne) SetNillableRole(a *authz.Role) *OrgInvitationUpdateOne {
	if a != nil {
		oiuo.SetRole(*a)
	}
	return oiuo
}

// ClearRole clears the value of the "role" field.
func (oiuo *OrgInvitationUpdateOne) ClearRole() *OrgInvitationUpdateOne {
	oiuo.mutation.ClearRole()
	return oiuo
}

// SetContext sets the "context" field.
func (oiuo *OrgInvitationUpdateOne) SetContext(bic biz.OrgInvitationContext) *OrgInvitationUpdateOne {
	oiuo.mutation.SetContext(bic)
	return oiuo
}

// SetNillableContext sets the "context" field if the given value is not nil.
func (oiuo *OrgInvitationUpdateOne) SetNillableContext(bic *biz.OrgInvitationContext) *OrgInvitationUpdateOne {
	if bic != nil {
		oiuo.SetContext(*bic)
	}
	return oiuo
}

// ClearContext clears the value of the "context" field.
func (oiuo *OrgInvitationUpdateOne) ClearContext() *OrgInvitationUpdateOne {
	oiuo.mutation.ClearContext()
	return oiuo
}

// SetOrganization sets the "organization" edge to the Organization entity.
func (oiuo *OrgInvitationUpdateOne) SetOrganization(o *Organization) *OrgInvitationUpdateOne {
	return oiuo.SetOrganizationID(o.ID)
}

// SetSender sets the "sender" edge to the User entity.
func (oiuo *OrgInvitationUpdateOne) SetSender(u *User) *OrgInvitationUpdateOne {
	return oiuo.SetSenderID(u.ID)
}

// Mutation returns the OrgInvitationMutation object of the builder.
func (oiuo *OrgInvitationUpdateOne) Mutation() *OrgInvitationMutation {
	return oiuo.mutation
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (oiuo *OrgInvitationUpdateOne) ClearOrganization() *OrgInvitationUpdateOne {
	oiuo.mutation.ClearOrganization()
	return oiuo
}

// ClearSender clears the "sender" edge to the User entity.
func (oiuo *OrgInvitationUpdateOne) ClearSender() *OrgInvitationUpdateOne {
	oiuo.mutation.ClearSender()
	return oiuo
}

// Where appends a list predicates to the OrgInvitationUpdate builder.
func (oiuo *OrgInvitationUpdateOne) Where(ps ...predicate.OrgInvitation) *OrgInvitationUpdateOne {
	oiuo.mutation.Where(ps...)
	return oiuo
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (oiuo *OrgInvitationUpdateOne) check() error {
	if v, ok := oiuo.mutation.Status(); ok {
		if err := orginvitation.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "OrgInvitation.status": %w`, err)}
		}
	}
	if v, ok := oiuo.mutation.Role(); ok {
		if err := orginvitation.RoleValidator(v); err != nil {
			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "OrgInvitation.role": %w`, err)}
		}
	}
	if oiuo.mutation.OrganizationCleared() && len(oiuo.mutation.OrganizationIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "OrgInvitation.organization"`)
	}
	if oiuo.mutation.SenderCleared() && len(oiuo.mutation.SenderIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "OrgInvitation.sender"`)
	}
	return nil
}

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

func (oiuo *OrgInvitationUpdateOne) sqlSave(ctx context.Context) (_node *OrgInvitation, err error) {
	if err := oiuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(orginvitation.Table, orginvitation.Columns, sqlgraph.NewFieldSpec(orginvitation.FieldID, field.TypeUUID))
	id, ok := oiuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "OrgInvitation.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := oiuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, orginvitation.FieldID)
		for _, f := range fields {
			if !orginvitation.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != orginvitation.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := oiuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := oiuo.mutation.Status(); ok {
		_spec.SetField(orginvitation.FieldStatus, field.TypeEnum, value)
	}
	if value, ok := oiuo.mutation.DeletedAt(); ok {
		_spec.SetField(orginvitation.FieldDeletedAt, field.TypeTime, value)
	}
	if oiuo.mutation.DeletedAtCleared() {
		_spec.ClearField(orginvitation.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := oiuo.mutation.Role(); ok {
		_spec.SetField(orginvitation.FieldRole, field.TypeEnum, value)
	}
	if oiuo.mutation.RoleCleared() {
		_spec.ClearField(orginvitation.FieldRole, field.TypeEnum)
	}
	if value, ok := oiuo.mutation.Context(); ok {
		_spec.SetField(orginvitation.FieldContext, field.TypeJSON, value)
	}
	if oiuo.mutation.ContextCleared() {
		_spec.ClearField(orginvitation.FieldContext, field.TypeJSON)
	}
	if oiuo.mutation.OrganizationCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.OrganizationTable,
			Columns: []string{orginvitation.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := oiuo.mutation.OrganizationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.OrganizationTable,
			Columns: []string{orginvitation.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if oiuo.mutation.SenderCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.SenderTable,
			Columns: []string{orginvitation.SenderColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := oiuo.mutation.SenderIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   orginvitation.SenderTable,
			Columns: []string{orginvitation.SenderColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(oiuo.modifiers...)
	_node = &OrgInvitation{config: oiuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, oiuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{orginvitation.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	oiuo.mutation.done = true
	return _node, nil
}
