// 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/Wei-Shaw/sub2api/ent/compositemodelroute"
	"github.com/Wei-Shaw/sub2api/ent/group"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
)

// CompositeModelRouteUpdate is the builder for updating CompositeModelRoute entities.
type CompositeModelRouteUpdate struct {
	config
	hooks    []Hook
	mutation *CompositeModelRouteMutation
}

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

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

// SetDeletedAt sets the "deleted_at" field.
func (_u *CompositeModelRouteUpdate) SetDeletedAt(v time.Time) *CompositeModelRouteUpdate {
	_u.mutation.SetDeletedAt(v)
	return _u
}

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

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

// SetGroupID sets the "group_id" field.
func (_u *CompositeModelRouteUpdate) SetGroupID(v int64) *CompositeModelRouteUpdate {
	_u.mutation.SetGroupID(v)
	return _u
}

// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableGroupID(v *int64) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetGroupID(*v)
	}
	return _u
}

// SetPublicModel sets the "public_model" field.
func (_u *CompositeModelRouteUpdate) SetPublicModel(v string) *CompositeModelRouteUpdate {
	_u.mutation.SetPublicModel(v)
	return _u
}

// SetNillablePublicModel sets the "public_model" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillablePublicModel(v *string) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetPublicModel(*v)
	}
	return _u
}

// SetMatchType sets the "match_type" field.
func (_u *CompositeModelRouteUpdate) SetMatchType(v string) *CompositeModelRouteUpdate {
	_u.mutation.SetMatchType(v)
	return _u
}

// SetNillableMatchType sets the "match_type" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableMatchType(v *string) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetMatchType(*v)
	}
	return _u
}

// SetTargetPlatform sets the "target_platform" field.
func (_u *CompositeModelRouteUpdate) SetTargetPlatform(v string) *CompositeModelRouteUpdate {
	_u.mutation.SetTargetPlatform(v)
	return _u
}

// SetNillableTargetPlatform sets the "target_platform" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableTargetPlatform(v *string) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetTargetPlatform(*v)
	}
	return _u
}

// SetUpstreamModel sets the "upstream_model" field.
func (_u *CompositeModelRouteUpdate) SetUpstreamModel(v string) *CompositeModelRouteUpdate {
	_u.mutation.SetUpstreamModel(v)
	return _u
}

// SetNillableUpstreamModel sets the "upstream_model" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableUpstreamModel(v *string) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetUpstreamModel(*v)
	}
	return _u
}

// SetEndpoint sets the "endpoint" field.
func (_u *CompositeModelRouteUpdate) SetEndpoint(v string) *CompositeModelRouteUpdate {
	_u.mutation.SetEndpoint(v)
	return _u
}

// SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableEndpoint(v *string) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetEndpoint(*v)
	}
	return _u
}

// SetPriority sets the "priority" field.
func (_u *CompositeModelRouteUpdate) SetPriority(v int) *CompositeModelRouteUpdate {
	_u.mutation.ResetPriority()
	_u.mutation.SetPriority(v)
	return _u
}

// SetNillablePriority sets the "priority" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillablePriority(v *int) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetPriority(*v)
	}
	return _u
}

// AddPriority adds value to the "priority" field.
func (_u *CompositeModelRouteUpdate) AddPriority(v int) *CompositeModelRouteUpdate {
	_u.mutation.AddPriority(v)
	return _u
}

// SetEnabled sets the "enabled" field.
func (_u *CompositeModelRouteUpdate) SetEnabled(v bool) *CompositeModelRouteUpdate {
	_u.mutation.SetEnabled(v)
	return _u
}

// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableEnabled(v *bool) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetEnabled(*v)
	}
	return _u
}

// SetNotes sets the "notes" field.
func (_u *CompositeModelRouteUpdate) SetNotes(v string) *CompositeModelRouteUpdate {
	_u.mutation.SetNotes(v)
	return _u
}

// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_u *CompositeModelRouteUpdate) SetNillableNotes(v *string) *CompositeModelRouteUpdate {
	if v != nil {
		_u.SetNotes(*v)
	}
	return _u
}

// ClearNotes clears the value of the "notes" field.
func (_u *CompositeModelRouteUpdate) ClearNotes() *CompositeModelRouteUpdate {
	_u.mutation.ClearNotes()
	return _u
}

// SetGroup sets the "group" edge to the Group entity.
func (_u *CompositeModelRouteUpdate) SetGroup(v *Group) *CompositeModelRouteUpdate {
	return _u.SetGroupID(v.ID)
}

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

// ClearGroup clears the "group" edge to the Group entity.
func (_u *CompositeModelRouteUpdate) ClearGroup() *CompositeModelRouteUpdate {
	_u.mutation.ClearGroup()
	return _u
}

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

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *CompositeModelRouteUpdate) 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 *CompositeModelRouteUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if compositemodelroute.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized compositemodelroute.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := compositemodelroute.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *CompositeModelRouteUpdate) check() error {
	if v, ok := _u.mutation.PublicModel(); ok {
		if err := compositemodelroute.PublicModelValidator(v); err != nil {
			return &ValidationError{Name: "public_model", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.public_model": %w`, err)}
		}
	}
	if v, ok := _u.mutation.MatchType(); ok {
		if err := compositemodelroute.MatchTypeValidator(v); err != nil {
			return &ValidationError{Name: "match_type", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.match_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.TargetPlatform(); ok {
		if err := compositemodelroute.TargetPlatformValidator(v); err != nil {
			return &ValidationError{Name: "target_platform", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.target_platform": %w`, err)}
		}
	}
	if v, ok := _u.mutation.UpstreamModel(); ok {
		if err := compositemodelroute.UpstreamModelValidator(v); err != nil {
			return &ValidationError{Name: "upstream_model", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.upstream_model": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Endpoint(); ok {
		if err := compositemodelroute.EndpointValidator(v); err != nil {
			return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.endpoint": %w`, err)}
		}
	}
	if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "CompositeModelRoute.group"`)
	}
	return nil
}

func (_u *CompositeModelRouteUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(compositemodelroute.Table, compositemodelroute.Columns, sqlgraph.NewFieldSpec(compositemodelroute.FieldID, field.TypeInt64))
	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.UpdatedAt(); ok {
		_spec.SetField(compositemodelroute.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(compositemodelroute.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(compositemodelroute.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.PublicModel(); ok {
		_spec.SetField(compositemodelroute.FieldPublicModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.MatchType(); ok {
		_spec.SetField(compositemodelroute.FieldMatchType, field.TypeString, value)
	}
	if value, ok := _u.mutation.TargetPlatform(); ok {
		_spec.SetField(compositemodelroute.FieldTargetPlatform, field.TypeString, value)
	}
	if value, ok := _u.mutation.UpstreamModel(); ok {
		_spec.SetField(compositemodelroute.FieldUpstreamModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.Endpoint(); ok {
		_spec.SetField(compositemodelroute.FieldEndpoint, field.TypeString, value)
	}
	if value, ok := _u.mutation.Priority(); ok {
		_spec.SetField(compositemodelroute.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPriority(); ok {
		_spec.AddField(compositemodelroute.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Enabled(); ok {
		_spec.SetField(compositemodelroute.FieldEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Notes(); ok {
		_spec.SetField(compositemodelroute.FieldNotes, field.TypeString, value)
	}
	if _u.mutation.NotesCleared() {
		_spec.ClearField(compositemodelroute.FieldNotes, field.TypeString)
	}
	if _u.mutation.GroupCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   compositemodelroute.GroupTable,
			Columns: []string{compositemodelroute.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   compositemodelroute.GroupTable,
			Columns: []string{compositemodelroute.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		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{compositemodelroute.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// CompositeModelRouteUpdateOne is the builder for updating a single CompositeModelRoute entity.
type CompositeModelRouteUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *CompositeModelRouteMutation
}

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

// SetDeletedAt sets the "deleted_at" field.
func (_u *CompositeModelRouteUpdateOne) SetDeletedAt(v time.Time) *CompositeModelRouteUpdateOne {
	_u.mutation.SetDeletedAt(v)
	return _u
}

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

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

// SetGroupID sets the "group_id" field.
func (_u *CompositeModelRouteUpdateOne) SetGroupID(v int64) *CompositeModelRouteUpdateOne {
	_u.mutation.SetGroupID(v)
	return _u
}

// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableGroupID(v *int64) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetGroupID(*v)
	}
	return _u
}

// SetPublicModel sets the "public_model" field.
func (_u *CompositeModelRouteUpdateOne) SetPublicModel(v string) *CompositeModelRouteUpdateOne {
	_u.mutation.SetPublicModel(v)
	return _u
}

// SetNillablePublicModel sets the "public_model" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillablePublicModel(v *string) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetPublicModel(*v)
	}
	return _u
}

// SetMatchType sets the "match_type" field.
func (_u *CompositeModelRouteUpdateOne) SetMatchType(v string) *CompositeModelRouteUpdateOne {
	_u.mutation.SetMatchType(v)
	return _u
}

// SetNillableMatchType sets the "match_type" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableMatchType(v *string) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetMatchType(*v)
	}
	return _u
}

// SetTargetPlatform sets the "target_platform" field.
func (_u *CompositeModelRouteUpdateOne) SetTargetPlatform(v string) *CompositeModelRouteUpdateOne {
	_u.mutation.SetTargetPlatform(v)
	return _u
}

// SetNillableTargetPlatform sets the "target_platform" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableTargetPlatform(v *string) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetTargetPlatform(*v)
	}
	return _u
}

// SetUpstreamModel sets the "upstream_model" field.
func (_u *CompositeModelRouteUpdateOne) SetUpstreamModel(v string) *CompositeModelRouteUpdateOne {
	_u.mutation.SetUpstreamModel(v)
	return _u
}

// SetNillableUpstreamModel sets the "upstream_model" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableUpstreamModel(v *string) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetUpstreamModel(*v)
	}
	return _u
}

// SetEndpoint sets the "endpoint" field.
func (_u *CompositeModelRouteUpdateOne) SetEndpoint(v string) *CompositeModelRouteUpdateOne {
	_u.mutation.SetEndpoint(v)
	return _u
}

// SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableEndpoint(v *string) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetEndpoint(*v)
	}
	return _u
}

// SetPriority sets the "priority" field.
func (_u *CompositeModelRouteUpdateOne) SetPriority(v int) *CompositeModelRouteUpdateOne {
	_u.mutation.ResetPriority()
	_u.mutation.SetPriority(v)
	return _u
}

// SetNillablePriority sets the "priority" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillablePriority(v *int) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetPriority(*v)
	}
	return _u
}

// AddPriority adds value to the "priority" field.
func (_u *CompositeModelRouteUpdateOne) AddPriority(v int) *CompositeModelRouteUpdateOne {
	_u.mutation.AddPriority(v)
	return _u
}

// SetEnabled sets the "enabled" field.
func (_u *CompositeModelRouteUpdateOne) SetEnabled(v bool) *CompositeModelRouteUpdateOne {
	_u.mutation.SetEnabled(v)
	return _u
}

// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableEnabled(v *bool) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetEnabled(*v)
	}
	return _u
}

// SetNotes sets the "notes" field.
func (_u *CompositeModelRouteUpdateOne) SetNotes(v string) *CompositeModelRouteUpdateOne {
	_u.mutation.SetNotes(v)
	return _u
}

// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_u *CompositeModelRouteUpdateOne) SetNillableNotes(v *string) *CompositeModelRouteUpdateOne {
	if v != nil {
		_u.SetNotes(*v)
	}
	return _u
}

// ClearNotes clears the value of the "notes" field.
func (_u *CompositeModelRouteUpdateOne) ClearNotes() *CompositeModelRouteUpdateOne {
	_u.mutation.ClearNotes()
	return _u
}

// SetGroup sets the "group" edge to the Group entity.
func (_u *CompositeModelRouteUpdateOne) SetGroup(v *Group) *CompositeModelRouteUpdateOne {
	return _u.SetGroupID(v.ID)
}

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

// ClearGroup clears the "group" edge to the Group entity.
func (_u *CompositeModelRouteUpdateOne) ClearGroup() *CompositeModelRouteUpdateOne {
	_u.mutation.ClearGroup()
	return _u
}

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

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

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *CompositeModelRouteUpdateOne) 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 *CompositeModelRouteUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if compositemodelroute.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized compositemodelroute.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := compositemodelroute.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *CompositeModelRouteUpdateOne) check() error {
	if v, ok := _u.mutation.PublicModel(); ok {
		if err := compositemodelroute.PublicModelValidator(v); err != nil {
			return &ValidationError{Name: "public_model", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.public_model": %w`, err)}
		}
	}
	if v, ok := _u.mutation.MatchType(); ok {
		if err := compositemodelroute.MatchTypeValidator(v); err != nil {
			return &ValidationError{Name: "match_type", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.match_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.TargetPlatform(); ok {
		if err := compositemodelroute.TargetPlatformValidator(v); err != nil {
			return &ValidationError{Name: "target_platform", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.target_platform": %w`, err)}
		}
	}
	if v, ok := _u.mutation.UpstreamModel(); ok {
		if err := compositemodelroute.UpstreamModelValidator(v); err != nil {
			return &ValidationError{Name: "upstream_model", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.upstream_model": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Endpoint(); ok {
		if err := compositemodelroute.EndpointValidator(v); err != nil {
			return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "CompositeModelRoute.endpoint": %w`, err)}
		}
	}
	if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "CompositeModelRoute.group"`)
	}
	return nil
}

func (_u *CompositeModelRouteUpdateOne) sqlSave(ctx context.Context) (_node *CompositeModelRoute, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(compositemodelroute.Table, compositemodelroute.Columns, sqlgraph.NewFieldSpec(compositemodelroute.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CompositeModelRoute.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, compositemodelroute.FieldID)
		for _, f := range fields {
			if !compositemodelroute.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != compositemodelroute.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.UpdatedAt(); ok {
		_spec.SetField(compositemodelroute.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(compositemodelroute.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(compositemodelroute.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.PublicModel(); ok {
		_spec.SetField(compositemodelroute.FieldPublicModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.MatchType(); ok {
		_spec.SetField(compositemodelroute.FieldMatchType, field.TypeString, value)
	}
	if value, ok := _u.mutation.TargetPlatform(); ok {
		_spec.SetField(compositemodelroute.FieldTargetPlatform, field.TypeString, value)
	}
	if value, ok := _u.mutation.UpstreamModel(); ok {
		_spec.SetField(compositemodelroute.FieldUpstreamModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.Endpoint(); ok {
		_spec.SetField(compositemodelroute.FieldEndpoint, field.TypeString, value)
	}
	if value, ok := _u.mutation.Priority(); ok {
		_spec.SetField(compositemodelroute.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPriority(); ok {
		_spec.AddField(compositemodelroute.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Enabled(); ok {
		_spec.SetField(compositemodelroute.FieldEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Notes(); ok {
		_spec.SetField(compositemodelroute.FieldNotes, field.TypeString, value)
	}
	if _u.mutation.NotesCleared() {
		_spec.ClearField(compositemodelroute.FieldNotes, field.TypeString)
	}
	if _u.mutation.GroupCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   compositemodelroute.GroupTable,
			Columns: []string{compositemodelroute.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   compositemodelroute.GroupTable,
			Columns: []string{compositemodelroute.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &CompositeModelRoute{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{compositemodelroute.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
