// 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/dialect/sql/sqljson"
	"entgo.io/ent/schema/field"
	"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
)

// ErrorPassthroughRuleUpdate is the builder for updating ErrorPassthroughRule entities.
type ErrorPassthroughRuleUpdate struct {
	config
	hooks    []Hook
	mutation *ErrorPassthroughRuleMutation
}

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

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

// SetName sets the "name" field.
func (_u *ErrorPassthroughRuleUpdate) SetName(v string) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetName(v)
	return _u
}

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

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

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

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

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

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

// SetErrorCodes sets the "error_codes" field.
func (_u *ErrorPassthroughRuleUpdate) SetErrorCodes(v []int) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetErrorCodes(v)
	return _u
}

// AppendErrorCodes appends value to the "error_codes" field.
func (_u *ErrorPassthroughRuleUpdate) AppendErrorCodes(v []int) *ErrorPassthroughRuleUpdate {
	_u.mutation.AppendErrorCodes(v)
	return _u
}

// ClearErrorCodes clears the value of the "error_codes" field.
func (_u *ErrorPassthroughRuleUpdate) ClearErrorCodes() *ErrorPassthroughRuleUpdate {
	_u.mutation.ClearErrorCodes()
	return _u
}

// SetKeywords sets the "keywords" field.
func (_u *ErrorPassthroughRuleUpdate) SetKeywords(v []string) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetKeywords(v)
	return _u
}

// AppendKeywords appends value to the "keywords" field.
func (_u *ErrorPassthroughRuleUpdate) AppendKeywords(v []string) *ErrorPassthroughRuleUpdate {
	_u.mutation.AppendKeywords(v)
	return _u
}

// ClearKeywords clears the value of the "keywords" field.
func (_u *ErrorPassthroughRuleUpdate) ClearKeywords() *ErrorPassthroughRuleUpdate {
	_u.mutation.ClearKeywords()
	return _u
}

// SetMatchMode sets the "match_mode" field.
func (_u *ErrorPassthroughRuleUpdate) SetMatchMode(v string) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetMatchMode(v)
	return _u
}

// SetNillableMatchMode sets the "match_mode" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdate) SetNillableMatchMode(v *string) *ErrorPassthroughRuleUpdate {
	if v != nil {
		_u.SetMatchMode(*v)
	}
	return _u
}

// SetPlatforms sets the "platforms" field.
func (_u *ErrorPassthroughRuleUpdate) SetPlatforms(v []string) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetPlatforms(v)
	return _u
}

// AppendPlatforms appends value to the "platforms" field.
func (_u *ErrorPassthroughRuleUpdate) AppendPlatforms(v []string) *ErrorPassthroughRuleUpdate {
	_u.mutation.AppendPlatforms(v)
	return _u
}

// ClearPlatforms clears the value of the "platforms" field.
func (_u *ErrorPassthroughRuleUpdate) ClearPlatforms() *ErrorPassthroughRuleUpdate {
	_u.mutation.ClearPlatforms()
	return _u
}

// SetPassthroughCode sets the "passthrough_code" field.
func (_u *ErrorPassthroughRuleUpdate) SetPassthroughCode(v bool) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetPassthroughCode(v)
	return _u
}

// SetNillablePassthroughCode sets the "passthrough_code" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdate) SetNillablePassthroughCode(v *bool) *ErrorPassthroughRuleUpdate {
	if v != nil {
		_u.SetPassthroughCode(*v)
	}
	return _u
}

// SetResponseCode sets the "response_code" field.
func (_u *ErrorPassthroughRuleUpdate) SetResponseCode(v int) *ErrorPassthroughRuleUpdate {
	_u.mutation.ResetResponseCode()
	_u.mutation.SetResponseCode(v)
	return _u
}

// SetNillableResponseCode sets the "response_code" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdate) SetNillableResponseCode(v *int) *ErrorPassthroughRuleUpdate {
	if v != nil {
		_u.SetResponseCode(*v)
	}
	return _u
}

// AddResponseCode adds value to the "response_code" field.
func (_u *ErrorPassthroughRuleUpdate) AddResponseCode(v int) *ErrorPassthroughRuleUpdate {
	_u.mutation.AddResponseCode(v)
	return _u
}

// ClearResponseCode clears the value of the "response_code" field.
func (_u *ErrorPassthroughRuleUpdate) ClearResponseCode() *ErrorPassthroughRuleUpdate {
	_u.mutation.ClearResponseCode()
	return _u
}

// SetPassthroughBody sets the "passthrough_body" field.
func (_u *ErrorPassthroughRuleUpdate) SetPassthroughBody(v bool) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetPassthroughBody(v)
	return _u
}

// SetNillablePassthroughBody sets the "passthrough_body" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdate) SetNillablePassthroughBody(v *bool) *ErrorPassthroughRuleUpdate {
	if v != nil {
		_u.SetPassthroughBody(*v)
	}
	return _u
}

// SetCustomMessage sets the "custom_message" field.
func (_u *ErrorPassthroughRuleUpdate) SetCustomMessage(v string) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetCustomMessage(v)
	return _u
}

// SetNillableCustomMessage sets the "custom_message" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdate) SetNillableCustomMessage(v *string) *ErrorPassthroughRuleUpdate {
	if v != nil {
		_u.SetCustomMessage(*v)
	}
	return _u
}

// ClearCustomMessage clears the value of the "custom_message" field.
func (_u *ErrorPassthroughRuleUpdate) ClearCustomMessage() *ErrorPassthroughRuleUpdate {
	_u.mutation.ClearCustomMessage()
	return _u
}

// SetDescription sets the "description" field.
func (_u *ErrorPassthroughRuleUpdate) SetDescription(v string) *ErrorPassthroughRuleUpdate {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdate) SetNillableDescription(v *string) *ErrorPassthroughRuleUpdate {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *ErrorPassthroughRuleUpdate) ClearDescription() *ErrorPassthroughRuleUpdate {
	_u.mutation.ClearDescription()
	return _u
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *ErrorPassthroughRuleUpdate) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := errorpassthroughrule.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.MatchMode(); ok {
		if err := errorpassthroughrule.MatchModeValidator(v); err != nil {
			return &ValidationError{Name: "match_mode", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.match_mode": %w`, err)}
		}
	}
	return nil
}

func (_u *ErrorPassthroughRuleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(errorpassthroughrule.Table, errorpassthroughrule.Columns, sqlgraph.NewFieldSpec(errorpassthroughrule.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(errorpassthroughrule.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(errorpassthroughrule.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Enabled(); ok {
		_spec.SetField(errorpassthroughrule.FieldEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Priority(); ok {
		_spec.SetField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPriority(); ok {
		_spec.AddField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ErrorCodes(); ok {
		_spec.SetField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedErrorCodes(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, errorpassthroughrule.FieldErrorCodes, value)
		})
	}
	if _u.mutation.ErrorCodesCleared() {
		_spec.ClearField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON)
	}
	if value, ok := _u.mutation.Keywords(); ok {
		_spec.SetField(errorpassthroughrule.FieldKeywords, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedKeywords(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, errorpassthroughrule.FieldKeywords, value)
		})
	}
	if _u.mutation.KeywordsCleared() {
		_spec.ClearField(errorpassthroughrule.FieldKeywords, field.TypeJSON)
	}
	if value, ok := _u.mutation.MatchMode(); ok {
		_spec.SetField(errorpassthroughrule.FieldMatchMode, field.TypeString, value)
	}
	if value, ok := _u.mutation.Platforms(); ok {
		_spec.SetField(errorpassthroughrule.FieldPlatforms, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedPlatforms(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, errorpassthroughrule.FieldPlatforms, value)
		})
	}
	if _u.mutation.PlatformsCleared() {
		_spec.ClearField(errorpassthroughrule.FieldPlatforms, field.TypeJSON)
	}
	if value, ok := _u.mutation.PassthroughCode(); ok {
		_spec.SetField(errorpassthroughrule.FieldPassthroughCode, field.TypeBool, value)
	}
	if value, ok := _u.mutation.ResponseCode(); ok {
		_spec.SetField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedResponseCode(); ok {
		_spec.AddField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
	}
	if _u.mutation.ResponseCodeCleared() {
		_spec.ClearField(errorpassthroughrule.FieldResponseCode, field.TypeInt)
	}
	if value, ok := _u.mutation.PassthroughBody(); ok {
		_spec.SetField(errorpassthroughrule.FieldPassthroughBody, field.TypeBool, value)
	}
	if value, ok := _u.mutation.CustomMessage(); ok {
		_spec.SetField(errorpassthroughrule.FieldCustomMessage, field.TypeString, value)
	}
	if _u.mutation.CustomMessageCleared() {
		_spec.ClearField(errorpassthroughrule.FieldCustomMessage, field.TypeString)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(errorpassthroughrule.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(errorpassthroughrule.FieldDescription, field.TypeString)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{errorpassthroughrule.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// ErrorPassthroughRuleUpdateOne is the builder for updating a single ErrorPassthroughRule entity.
type ErrorPassthroughRuleUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ErrorPassthroughRuleMutation
}

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

// SetName sets the "name" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetName(v string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetName(v)
	return _u
}

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

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

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

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

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

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

// SetErrorCodes sets the "error_codes" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetErrorCodes(v []int) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetErrorCodes(v)
	return _u
}

// AppendErrorCodes appends value to the "error_codes" field.
func (_u *ErrorPassthroughRuleUpdateOne) AppendErrorCodes(v []int) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.AppendErrorCodes(v)
	return _u
}

// ClearErrorCodes clears the value of the "error_codes" field.
func (_u *ErrorPassthroughRuleUpdateOne) ClearErrorCodes() *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ClearErrorCodes()
	return _u
}

// SetKeywords sets the "keywords" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetKeywords(v []string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetKeywords(v)
	return _u
}

// AppendKeywords appends value to the "keywords" field.
func (_u *ErrorPassthroughRuleUpdateOne) AppendKeywords(v []string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.AppendKeywords(v)
	return _u
}

// ClearKeywords clears the value of the "keywords" field.
func (_u *ErrorPassthroughRuleUpdateOne) ClearKeywords() *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ClearKeywords()
	return _u
}

// SetMatchMode sets the "match_mode" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetMatchMode(v string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetMatchMode(v)
	return _u
}

// SetNillableMatchMode sets the "match_mode" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdateOne) SetNillableMatchMode(v *string) *ErrorPassthroughRuleUpdateOne {
	if v != nil {
		_u.SetMatchMode(*v)
	}
	return _u
}

// SetPlatforms sets the "platforms" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetPlatforms(v []string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetPlatforms(v)
	return _u
}

// AppendPlatforms appends value to the "platforms" field.
func (_u *ErrorPassthroughRuleUpdateOne) AppendPlatforms(v []string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.AppendPlatforms(v)
	return _u
}

// ClearPlatforms clears the value of the "platforms" field.
func (_u *ErrorPassthroughRuleUpdateOne) ClearPlatforms() *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ClearPlatforms()
	return _u
}

// SetPassthroughCode sets the "passthrough_code" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetPassthroughCode(v bool) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetPassthroughCode(v)
	return _u
}

// SetNillablePassthroughCode sets the "passthrough_code" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePassthroughCode(v *bool) *ErrorPassthroughRuleUpdateOne {
	if v != nil {
		_u.SetPassthroughCode(*v)
	}
	return _u
}

// SetResponseCode sets the "response_code" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetResponseCode(v int) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ResetResponseCode()
	_u.mutation.SetResponseCode(v)
	return _u
}

// SetNillableResponseCode sets the "response_code" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdateOne) SetNillableResponseCode(v *int) *ErrorPassthroughRuleUpdateOne {
	if v != nil {
		_u.SetResponseCode(*v)
	}
	return _u
}

// AddResponseCode adds value to the "response_code" field.
func (_u *ErrorPassthroughRuleUpdateOne) AddResponseCode(v int) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.AddResponseCode(v)
	return _u
}

// ClearResponseCode clears the value of the "response_code" field.
func (_u *ErrorPassthroughRuleUpdateOne) ClearResponseCode() *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ClearResponseCode()
	return _u
}

// SetPassthroughBody sets the "passthrough_body" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetPassthroughBody(v bool) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetPassthroughBody(v)
	return _u
}

// SetNillablePassthroughBody sets the "passthrough_body" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePassthroughBody(v *bool) *ErrorPassthroughRuleUpdateOne {
	if v != nil {
		_u.SetPassthroughBody(*v)
	}
	return _u
}

// SetCustomMessage sets the "custom_message" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetCustomMessage(v string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetCustomMessage(v)
	return _u
}

// SetNillableCustomMessage sets the "custom_message" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdateOne) SetNillableCustomMessage(v *string) *ErrorPassthroughRuleUpdateOne {
	if v != nil {
		_u.SetCustomMessage(*v)
	}
	return _u
}

// ClearCustomMessage clears the value of the "custom_message" field.
func (_u *ErrorPassthroughRuleUpdateOne) ClearCustomMessage() *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ClearCustomMessage()
	return _u
}

// SetDescription sets the "description" field.
func (_u *ErrorPassthroughRuleUpdateOne) SetDescription(v string) *ErrorPassthroughRuleUpdateOne {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ErrorPassthroughRuleUpdateOne) SetNillableDescription(v *string) *ErrorPassthroughRuleUpdateOne {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *ErrorPassthroughRuleUpdateOne) ClearDescription() *ErrorPassthroughRuleUpdateOne {
	_u.mutation.ClearDescription()
	return _u
}

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

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *ErrorPassthroughRuleUpdateOne) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := errorpassthroughrule.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.MatchMode(); ok {
		if err := errorpassthroughrule.MatchModeValidator(v); err != nil {
			return &ValidationError{Name: "match_mode", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.match_mode": %w`, err)}
		}
	}
	return nil
}

func (_u *ErrorPassthroughRuleUpdateOne) sqlSave(ctx context.Context) (_node *ErrorPassthroughRule, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(errorpassthroughrule.Table, errorpassthroughrule.Columns, sqlgraph.NewFieldSpec(errorpassthroughrule.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ErrorPassthroughRule.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, errorpassthroughrule.FieldID)
		for _, f := range fields {
			if !errorpassthroughrule.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != errorpassthroughrule.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(errorpassthroughrule.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(errorpassthroughrule.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Enabled(); ok {
		_spec.SetField(errorpassthroughrule.FieldEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Priority(); ok {
		_spec.SetField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPriority(); ok {
		_spec.AddField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ErrorCodes(); ok {
		_spec.SetField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedErrorCodes(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, errorpassthroughrule.FieldErrorCodes, value)
		})
	}
	if _u.mutation.ErrorCodesCleared() {
		_spec.ClearField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON)
	}
	if value, ok := _u.mutation.Keywords(); ok {
		_spec.SetField(errorpassthroughrule.FieldKeywords, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedKeywords(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, errorpassthroughrule.FieldKeywords, value)
		})
	}
	if _u.mutation.KeywordsCleared() {
		_spec.ClearField(errorpassthroughrule.FieldKeywords, field.TypeJSON)
	}
	if value, ok := _u.mutation.MatchMode(); ok {
		_spec.SetField(errorpassthroughrule.FieldMatchMode, field.TypeString, value)
	}
	if value, ok := _u.mutation.Platforms(); ok {
		_spec.SetField(errorpassthroughrule.FieldPlatforms, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedPlatforms(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, errorpassthroughrule.FieldPlatforms, value)
		})
	}
	if _u.mutation.PlatformsCleared() {
		_spec.ClearField(errorpassthroughrule.FieldPlatforms, field.TypeJSON)
	}
	if value, ok := _u.mutation.PassthroughCode(); ok {
		_spec.SetField(errorpassthroughrule.FieldPassthroughCode, field.TypeBool, value)
	}
	if value, ok := _u.mutation.ResponseCode(); ok {
		_spec.SetField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedResponseCode(); ok {
		_spec.AddField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
	}
	if _u.mutation.ResponseCodeCleared() {
		_spec.ClearField(errorpassthroughrule.FieldResponseCode, field.TypeInt)
	}
	if value, ok := _u.mutation.PassthroughBody(); ok {
		_spec.SetField(errorpassthroughrule.FieldPassthroughBody, field.TypeBool, value)
	}
	if value, ok := _u.mutation.CustomMessage(); ok {
		_spec.SetField(errorpassthroughrule.FieldCustomMessage, field.TypeString, value)
	}
	if _u.mutation.CustomMessageCleared() {
		_spec.ClearField(errorpassthroughrule.FieldCustomMessage, field.TypeString)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(errorpassthroughrule.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(errorpassthroughrule.FieldDescription, field.TypeString)
	}
	_node = &ErrorPassthroughRule{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{errorpassthroughrule.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
