// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"galileo/ent/api"
	"galileo/ent/predicate"
	"time"

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

// APIUpdate is the builder for updating Api entities.
type APIUpdate struct {
	config
	hooks    []Hook
	mutation *APIMutation
}

// Where appends a list predicates to the APIUpdate builder.
func (au *APIUpdate) Where(ps ...predicate.Api) *APIUpdate {
	au.mutation.Where(ps...)
	return au
}

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

// SetURL sets the "url" field.
func (au *APIUpdate) SetURL(s string) *APIUpdate {
	au.mutation.SetURL(s)
	return au
}

// SetType sets the "type" field.
func (au *APIUpdate) SetType(i int8) *APIUpdate {
	au.mutation.ResetType()
	au.mutation.SetType(i)
	return au
}

// AddType adds i to the "type" field.
func (au *APIUpdate) AddType(i int8) *APIUpdate {
	au.mutation.AddType(i)
	return au
}

// SetStatus sets the "status" field.
func (au *APIUpdate) SetStatus(i int8) *APIUpdate {
	au.mutation.ResetStatus()
	au.mutation.SetStatus(i)
	return au
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (au *APIUpdate) SetNillableStatus(i *int8) *APIUpdate {
	if i != nil {
		au.SetStatus(*i)
	}
	return au
}

// AddStatus adds i to the "status" field.
func (au *APIUpdate) AddStatus(i int8) *APIUpdate {
	au.mutation.AddStatus(i)
	return au
}

// SetHeaders sets the "headers" field.
func (au *APIUpdate) SetHeaders(s string) *APIUpdate {
	au.mutation.SetHeaders(s)
	return au
}

// SetNillableHeaders sets the "headers" field if the given value is not nil.
func (au *APIUpdate) SetNillableHeaders(s *string) *APIUpdate {
	if s != nil {
		au.SetHeaders(*s)
	}
	return au
}

// ClearHeaders clears the value of the "headers" field.
func (au *APIUpdate) ClearHeaders() *APIUpdate {
	au.mutation.ClearHeaders()
	return au
}

// SetBody sets the "body" field.
func (au *APIUpdate) SetBody(s string) *APIUpdate {
	au.mutation.SetBody(s)
	return au
}

// SetNillableBody sets the "body" field if the given value is not nil.
func (au *APIUpdate) SetNillableBody(s *string) *APIUpdate {
	if s != nil {
		au.SetBody(*s)
	}
	return au
}

// ClearBody clears the value of the "body" field.
func (au *APIUpdate) ClearBody() *APIUpdate {
	au.mutation.ClearBody()
	return au
}

// SetLabel sets the "label" field.
func (au *APIUpdate) SetLabel(s string) *APIUpdate {
	au.mutation.SetLabel(s)
	return au
}

// SetNillableLabel sets the "label" field if the given value is not nil.
func (au *APIUpdate) SetNillableLabel(s *string) *APIUpdate {
	if s != nil {
		au.SetLabel(*s)
	}
	return au
}

// ClearLabel clears the value of the "label" field.
func (au *APIUpdate) ClearLabel() *APIUpdate {
	au.mutation.ClearLabel()
	return au
}

// SetQueryParams sets the "query_params" field.
func (au *APIUpdate) SetQueryParams(s string) *APIUpdate {
	au.mutation.SetQueryParams(s)
	return au
}

// SetNillableQueryParams sets the "query_params" field if the given value is not nil.
func (au *APIUpdate) SetNillableQueryParams(s *string) *APIUpdate {
	if s != nil {
		au.SetQueryParams(*s)
	}
	return au
}

// ClearQueryParams clears the value of the "query_params" field.
func (au *APIUpdate) ClearQueryParams() *APIUpdate {
	au.mutation.ClearQueryParams()
	return au
}

// SetResponse sets the "response" field.
func (au *APIUpdate) SetResponse(s string) *APIUpdate {
	au.mutation.SetResponse(s)
	return au
}

// SetNillableResponse sets the "response" field if the given value is not nil.
func (au *APIUpdate) SetNillableResponse(s *string) *APIUpdate {
	if s != nil {
		au.SetResponse(*s)
	}
	return au
}

// ClearResponse clears the value of the "response" field.
func (au *APIUpdate) ClearResponse() *APIUpdate {
	au.mutation.ClearResponse()
	return au
}

// SetModule sets the "module" field.
func (au *APIUpdate) SetModule(s string) *APIUpdate {
	au.mutation.SetModule(s)
	return au
}

// SetNillableModule sets the "module" field if the given value is not nil.
func (au *APIUpdate) SetNillableModule(s *string) *APIUpdate {
	if s != nil {
		au.SetModule(*s)
	}
	return au
}

// ClearModule clears the value of the "module" field.
func (au *APIUpdate) ClearModule() *APIUpdate {
	au.mutation.ClearModule()
	return au
}

// SetDescription sets the "description" field.
func (au *APIUpdate) SetDescription(s string) *APIUpdate {
	au.mutation.SetDescription(s)
	return au
}

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

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

// SetIncludeFiles sets the "include_files" field.
func (au *APIUpdate) SetIncludeFiles(s string) *APIUpdate {
	au.mutation.SetIncludeFiles(s)
	return au
}

// SetNillableIncludeFiles sets the "include_files" field if the given value is not nil.
func (au *APIUpdate) SetNillableIncludeFiles(s *string) *APIUpdate {
	if s != nil {
		au.SetIncludeFiles(*s)
	}
	return au
}

// ClearIncludeFiles clears the value of the "include_files" field.
func (au *APIUpdate) ClearIncludeFiles() *APIUpdate {
	au.mutation.ClearIncludeFiles()
	return au
}

// SetUpdateAt sets the "update_at" field.
func (au *APIUpdate) SetUpdateAt(t time.Time) *APIUpdate {
	au.mutation.SetUpdateAt(t)
	return au
}

// ClearUpdateAt clears the value of the "update_at" field.
func (au *APIUpdate) ClearUpdateAt() *APIUpdate {
	au.mutation.ClearUpdateAt()
	return au
}

// SetUpdateBy sets the "update_by" field.
func (au *APIUpdate) SetUpdateBy(u uint32) *APIUpdate {
	au.mutation.ResetUpdateBy()
	au.mutation.SetUpdateBy(u)
	return au
}

// SetNillableUpdateBy sets the "update_by" field if the given value is not nil.
func (au *APIUpdate) SetNillableUpdateBy(u *uint32) *APIUpdate {
	if u != nil {
		au.SetUpdateBy(*u)
	}
	return au
}

// AddUpdateBy adds u to the "update_by" field.
func (au *APIUpdate) AddUpdateBy(u int32) *APIUpdate {
	au.mutation.AddUpdateBy(u)
	return au
}

// ClearUpdateBy clears the value of the "update_by" field.
func (au *APIUpdate) ClearUpdateBy() *APIUpdate {
	au.mutation.ClearUpdateBy()
	return au
}

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

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

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

// SetDeletedBy sets the "deleted_by" field.
func (au *APIUpdate) SetDeletedBy(u uint32) *APIUpdate {
	au.mutation.ResetDeletedBy()
	au.mutation.SetDeletedBy(u)
	return au
}

// SetNillableDeletedBy sets the "deleted_by" field if the given value is not nil.
func (au *APIUpdate) SetNillableDeletedBy(u *uint32) *APIUpdate {
	if u != nil {
		au.SetDeletedBy(*u)
	}
	return au
}

// AddDeletedBy adds u to the "deleted_by" field.
func (au *APIUpdate) AddDeletedBy(u int32) *APIUpdate {
	au.mutation.AddDeletedBy(u)
	return au
}

// ClearDeletedBy clears the value of the "deleted_by" field.
func (au *APIUpdate) ClearDeletedBy() *APIUpdate {
	au.mutation.ClearDeletedBy()
	return au
}

// Mutation returns the APIMutation object of the builder.
func (au *APIUpdate) Mutation() *APIMutation {
	return au.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (au *APIUpdate) defaults() {
	if _, ok := au.mutation.UpdateAt(); !ok && !au.mutation.UpdateAtCleared() {
		v := api.UpdateDefaultUpdateAt()
		au.mutation.SetUpdateAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (au *APIUpdate) check() error {
	if v, ok := au.mutation.Name(); ok {
		if err := api.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Api.name": %w`, err)}
		}
	}
	if v, ok := au.mutation.URL(); ok {
		if err := api.URLValidator(v); err != nil {
			return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Api.url": %w`, err)}
		}
	}
	if v, ok := au.mutation.GetType(); ok {
		if err := api.TypeValidator(v); err != nil {
			return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Api.type": %w`, err)}
		}
	}
	return nil
}

func (au *APIUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := au.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(api.Table, api.Columns, sqlgraph.NewFieldSpec(api.FieldID, field.TypeInt32))
	if ps := au.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := au.mutation.Name(); ok {
		_spec.SetField(api.FieldName, field.TypeString, value)
	}
	if value, ok := au.mutation.URL(); ok {
		_spec.SetField(api.FieldURL, field.TypeString, value)
	}
	if value, ok := au.mutation.GetType(); ok {
		_spec.SetField(api.FieldType, field.TypeInt8, value)
	}
	if value, ok := au.mutation.AddedType(); ok {
		_spec.AddField(api.FieldType, field.TypeInt8, value)
	}
	if value, ok := au.mutation.Status(); ok {
		_spec.SetField(api.FieldStatus, field.TypeInt8, value)
	}
	if value, ok := au.mutation.AddedStatus(); ok {
		_spec.AddField(api.FieldStatus, field.TypeInt8, value)
	}
	if value, ok := au.mutation.Headers(); ok {
		_spec.SetField(api.FieldHeaders, field.TypeString, value)
	}
	if au.mutation.HeadersCleared() {
		_spec.ClearField(api.FieldHeaders, field.TypeString)
	}
	if value, ok := au.mutation.Body(); ok {
		_spec.SetField(api.FieldBody, field.TypeString, value)
	}
	if au.mutation.BodyCleared() {
		_spec.ClearField(api.FieldBody, field.TypeString)
	}
	if value, ok := au.mutation.Label(); ok {
		_spec.SetField(api.FieldLabel, field.TypeString, value)
	}
	if au.mutation.LabelCleared() {
		_spec.ClearField(api.FieldLabel, field.TypeString)
	}
	if value, ok := au.mutation.QueryParams(); ok {
		_spec.SetField(api.FieldQueryParams, field.TypeString, value)
	}
	if au.mutation.QueryParamsCleared() {
		_spec.ClearField(api.FieldQueryParams, field.TypeString)
	}
	if value, ok := au.mutation.Response(); ok {
		_spec.SetField(api.FieldResponse, field.TypeString, value)
	}
	if au.mutation.ResponseCleared() {
		_spec.ClearField(api.FieldResponse, field.TypeString)
	}
	if value, ok := au.mutation.Module(); ok {
		_spec.SetField(api.FieldModule, field.TypeString, value)
	}
	if au.mutation.ModuleCleared() {
		_spec.ClearField(api.FieldModule, field.TypeString)
	}
	if value, ok := au.mutation.Description(); ok {
		_spec.SetField(api.FieldDescription, field.TypeString, value)
	}
	if au.mutation.DescriptionCleared() {
		_spec.ClearField(api.FieldDescription, field.TypeString)
	}
	if value, ok := au.mutation.IncludeFiles(); ok {
		_spec.SetField(api.FieldIncludeFiles, field.TypeString, value)
	}
	if au.mutation.IncludeFilesCleared() {
		_spec.ClearField(api.FieldIncludeFiles, field.TypeString)
	}
	if value, ok := au.mutation.UpdateAt(); ok {
		_spec.SetField(api.FieldUpdateAt, field.TypeTime, value)
	}
	if au.mutation.UpdateAtCleared() {
		_spec.ClearField(api.FieldUpdateAt, field.TypeTime)
	}
	if value, ok := au.mutation.UpdateBy(); ok {
		_spec.SetField(api.FieldUpdateBy, field.TypeUint32, value)
	}
	if value, ok := au.mutation.AddedUpdateBy(); ok {
		_spec.AddField(api.FieldUpdateBy, field.TypeUint32, value)
	}
	if au.mutation.UpdateByCleared() {
		_spec.ClearField(api.FieldUpdateBy, field.TypeUint32)
	}
	if value, ok := au.mutation.DeletedAt(); ok {
		_spec.SetField(api.FieldDeletedAt, field.TypeTime, value)
	}
	if au.mutation.DeletedAtCleared() {
		_spec.ClearField(api.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := au.mutation.DeletedBy(); ok {
		_spec.SetField(api.FieldDeletedBy, field.TypeUint32, value)
	}
	if value, ok := au.mutation.AddedDeletedBy(); ok {
		_spec.AddField(api.FieldDeletedBy, field.TypeUint32, value)
	}
	if au.mutation.DeletedByCleared() {
		_spec.ClearField(api.FieldDeletedBy, field.TypeUint32)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{api.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	au.mutation.done = true
	return n, nil
}

// APIUpdateOne is the builder for updating a single Api entity.
type APIUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *APIMutation
}

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

// SetURL sets the "url" field.
func (auo *APIUpdateOne) SetURL(s string) *APIUpdateOne {
	auo.mutation.SetURL(s)
	return auo
}

// SetType sets the "type" field.
func (auo *APIUpdateOne) SetType(i int8) *APIUpdateOne {
	auo.mutation.ResetType()
	auo.mutation.SetType(i)
	return auo
}

// AddType adds i to the "type" field.
func (auo *APIUpdateOne) AddType(i int8) *APIUpdateOne {
	auo.mutation.AddType(i)
	return auo
}

// SetStatus sets the "status" field.
func (auo *APIUpdateOne) SetStatus(i int8) *APIUpdateOne {
	auo.mutation.ResetStatus()
	auo.mutation.SetStatus(i)
	return auo
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableStatus(i *int8) *APIUpdateOne {
	if i != nil {
		auo.SetStatus(*i)
	}
	return auo
}

// AddStatus adds i to the "status" field.
func (auo *APIUpdateOne) AddStatus(i int8) *APIUpdateOne {
	auo.mutation.AddStatus(i)
	return auo
}

// SetHeaders sets the "headers" field.
func (auo *APIUpdateOne) SetHeaders(s string) *APIUpdateOne {
	auo.mutation.SetHeaders(s)
	return auo
}

// SetNillableHeaders sets the "headers" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableHeaders(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetHeaders(*s)
	}
	return auo
}

// ClearHeaders clears the value of the "headers" field.
func (auo *APIUpdateOne) ClearHeaders() *APIUpdateOne {
	auo.mutation.ClearHeaders()
	return auo
}

// SetBody sets the "body" field.
func (auo *APIUpdateOne) SetBody(s string) *APIUpdateOne {
	auo.mutation.SetBody(s)
	return auo
}

// SetNillableBody sets the "body" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableBody(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetBody(*s)
	}
	return auo
}

// ClearBody clears the value of the "body" field.
func (auo *APIUpdateOne) ClearBody() *APIUpdateOne {
	auo.mutation.ClearBody()
	return auo
}

// SetLabel sets the "label" field.
func (auo *APIUpdateOne) SetLabel(s string) *APIUpdateOne {
	auo.mutation.SetLabel(s)
	return auo
}

// SetNillableLabel sets the "label" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableLabel(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetLabel(*s)
	}
	return auo
}

// ClearLabel clears the value of the "label" field.
func (auo *APIUpdateOne) ClearLabel() *APIUpdateOne {
	auo.mutation.ClearLabel()
	return auo
}

// SetQueryParams sets the "query_params" field.
func (auo *APIUpdateOne) SetQueryParams(s string) *APIUpdateOne {
	auo.mutation.SetQueryParams(s)
	return auo
}

// SetNillableQueryParams sets the "query_params" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableQueryParams(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetQueryParams(*s)
	}
	return auo
}

// ClearQueryParams clears the value of the "query_params" field.
func (auo *APIUpdateOne) ClearQueryParams() *APIUpdateOne {
	auo.mutation.ClearQueryParams()
	return auo
}

// SetResponse sets the "response" field.
func (auo *APIUpdateOne) SetResponse(s string) *APIUpdateOne {
	auo.mutation.SetResponse(s)
	return auo
}

// SetNillableResponse sets the "response" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableResponse(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetResponse(*s)
	}
	return auo
}

// ClearResponse clears the value of the "response" field.
func (auo *APIUpdateOne) ClearResponse() *APIUpdateOne {
	auo.mutation.ClearResponse()
	return auo
}

// SetModule sets the "module" field.
func (auo *APIUpdateOne) SetModule(s string) *APIUpdateOne {
	auo.mutation.SetModule(s)
	return auo
}

// SetNillableModule sets the "module" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableModule(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetModule(*s)
	}
	return auo
}

// ClearModule clears the value of the "module" field.
func (auo *APIUpdateOne) ClearModule() *APIUpdateOne {
	auo.mutation.ClearModule()
	return auo
}

// SetDescription sets the "description" field.
func (auo *APIUpdateOne) SetDescription(s string) *APIUpdateOne {
	auo.mutation.SetDescription(s)
	return auo
}

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

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

// SetIncludeFiles sets the "include_files" field.
func (auo *APIUpdateOne) SetIncludeFiles(s string) *APIUpdateOne {
	auo.mutation.SetIncludeFiles(s)
	return auo
}

// SetNillableIncludeFiles sets the "include_files" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableIncludeFiles(s *string) *APIUpdateOne {
	if s != nil {
		auo.SetIncludeFiles(*s)
	}
	return auo
}

// ClearIncludeFiles clears the value of the "include_files" field.
func (auo *APIUpdateOne) ClearIncludeFiles() *APIUpdateOne {
	auo.mutation.ClearIncludeFiles()
	return auo
}

// SetUpdateAt sets the "update_at" field.
func (auo *APIUpdateOne) SetUpdateAt(t time.Time) *APIUpdateOne {
	auo.mutation.SetUpdateAt(t)
	return auo
}

// ClearUpdateAt clears the value of the "update_at" field.
func (auo *APIUpdateOne) ClearUpdateAt() *APIUpdateOne {
	auo.mutation.ClearUpdateAt()
	return auo
}

// SetUpdateBy sets the "update_by" field.
func (auo *APIUpdateOne) SetUpdateBy(u uint32) *APIUpdateOne {
	auo.mutation.ResetUpdateBy()
	auo.mutation.SetUpdateBy(u)
	return auo
}

// SetNillableUpdateBy sets the "update_by" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableUpdateBy(u *uint32) *APIUpdateOne {
	if u != nil {
		auo.SetUpdateBy(*u)
	}
	return auo
}

// AddUpdateBy adds u to the "update_by" field.
func (auo *APIUpdateOne) AddUpdateBy(u int32) *APIUpdateOne {
	auo.mutation.AddUpdateBy(u)
	return auo
}

// ClearUpdateBy clears the value of the "update_by" field.
func (auo *APIUpdateOne) ClearUpdateBy() *APIUpdateOne {
	auo.mutation.ClearUpdateBy()
	return auo
}

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

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

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

// SetDeletedBy sets the "deleted_by" field.
func (auo *APIUpdateOne) SetDeletedBy(u uint32) *APIUpdateOne {
	auo.mutation.ResetDeletedBy()
	auo.mutation.SetDeletedBy(u)
	return auo
}

// SetNillableDeletedBy sets the "deleted_by" field if the given value is not nil.
func (auo *APIUpdateOne) SetNillableDeletedBy(u *uint32) *APIUpdateOne {
	if u != nil {
		auo.SetDeletedBy(*u)
	}
	return auo
}

// AddDeletedBy adds u to the "deleted_by" field.
func (auo *APIUpdateOne) AddDeletedBy(u int32) *APIUpdateOne {
	auo.mutation.AddDeletedBy(u)
	return auo
}

// ClearDeletedBy clears the value of the "deleted_by" field.
func (auo *APIUpdateOne) ClearDeletedBy() *APIUpdateOne {
	auo.mutation.ClearDeletedBy()
	return auo
}

// Mutation returns the APIMutation object of the builder.
func (auo *APIUpdateOne) Mutation() *APIMutation {
	return auo.mutation
}

// Where appends a list predicates to the APIUpdate builder.
func (auo *APIUpdateOne) Where(ps ...predicate.Api) *APIUpdateOne {
	auo.mutation.Where(ps...)
	return auo
}

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

// Save executes the query and returns the updated Api entity.
func (auo *APIUpdateOne) Save(ctx context.Context) (*Api, error) {
	auo.defaults()
	return withHooks[*Api, APIMutation](ctx, auo.sqlSave, auo.mutation, auo.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (auo *APIUpdateOne) defaults() {
	if _, ok := auo.mutation.UpdateAt(); !ok && !auo.mutation.UpdateAtCleared() {
		v := api.UpdateDefaultUpdateAt()
		auo.mutation.SetUpdateAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (auo *APIUpdateOne) check() error {
	if v, ok := auo.mutation.Name(); ok {
		if err := api.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Api.name": %w`, err)}
		}
	}
	if v, ok := auo.mutation.URL(); ok {
		if err := api.URLValidator(v); err != nil {
			return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Api.url": %w`, err)}
		}
	}
	if v, ok := auo.mutation.GetType(); ok {
		if err := api.TypeValidator(v); err != nil {
			return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Api.type": %w`, err)}
		}
	}
	return nil
}

func (auo *APIUpdateOne) sqlSave(ctx context.Context) (_node *Api, err error) {
	if err := auo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(api.Table, api.Columns, sqlgraph.NewFieldSpec(api.FieldID, field.TypeInt32))
	id, ok := auo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Api.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := auo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, api.FieldID)
		for _, f := range fields {
			if !api.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != api.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := auo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := auo.mutation.Name(); ok {
		_spec.SetField(api.FieldName, field.TypeString, value)
	}
	if value, ok := auo.mutation.URL(); ok {
		_spec.SetField(api.FieldURL, field.TypeString, value)
	}
	if value, ok := auo.mutation.GetType(); ok {
		_spec.SetField(api.FieldType, field.TypeInt8, value)
	}
	if value, ok := auo.mutation.AddedType(); ok {
		_spec.AddField(api.FieldType, field.TypeInt8, value)
	}
	if value, ok := auo.mutation.Status(); ok {
		_spec.SetField(api.FieldStatus, field.TypeInt8, value)
	}
	if value, ok := auo.mutation.AddedStatus(); ok {
		_spec.AddField(api.FieldStatus, field.TypeInt8, value)
	}
	if value, ok := auo.mutation.Headers(); ok {
		_spec.SetField(api.FieldHeaders, field.TypeString, value)
	}
	if auo.mutation.HeadersCleared() {
		_spec.ClearField(api.FieldHeaders, field.TypeString)
	}
	if value, ok := auo.mutation.Body(); ok {
		_spec.SetField(api.FieldBody, field.TypeString, value)
	}
	if auo.mutation.BodyCleared() {
		_spec.ClearField(api.FieldBody, field.TypeString)
	}
	if value, ok := auo.mutation.Label(); ok {
		_spec.SetField(api.FieldLabel, field.TypeString, value)
	}
	if auo.mutation.LabelCleared() {
		_spec.ClearField(api.FieldLabel, field.TypeString)
	}
	if value, ok := auo.mutation.QueryParams(); ok {
		_spec.SetField(api.FieldQueryParams, field.TypeString, value)
	}
	if auo.mutation.QueryParamsCleared() {
		_spec.ClearField(api.FieldQueryParams, field.TypeString)
	}
	if value, ok := auo.mutation.Response(); ok {
		_spec.SetField(api.FieldResponse, field.TypeString, value)
	}
	if auo.mutation.ResponseCleared() {
		_spec.ClearField(api.FieldResponse, field.TypeString)
	}
	if value, ok := auo.mutation.Module(); ok {
		_spec.SetField(api.FieldModule, field.TypeString, value)
	}
	if auo.mutation.ModuleCleared() {
		_spec.ClearField(api.FieldModule, field.TypeString)
	}
	if value, ok := auo.mutation.Description(); ok {
		_spec.SetField(api.FieldDescription, field.TypeString, value)
	}
	if auo.mutation.DescriptionCleared() {
		_spec.ClearField(api.FieldDescription, field.TypeString)
	}
	if value, ok := auo.mutation.IncludeFiles(); ok {
		_spec.SetField(api.FieldIncludeFiles, field.TypeString, value)
	}
	if auo.mutation.IncludeFilesCleared() {
		_spec.ClearField(api.FieldIncludeFiles, field.TypeString)
	}
	if value, ok := auo.mutation.UpdateAt(); ok {
		_spec.SetField(api.FieldUpdateAt, field.TypeTime, value)
	}
	if auo.mutation.UpdateAtCleared() {
		_spec.ClearField(api.FieldUpdateAt, field.TypeTime)
	}
	if value, ok := auo.mutation.UpdateBy(); ok {
		_spec.SetField(api.FieldUpdateBy, field.TypeUint32, value)
	}
	if value, ok := auo.mutation.AddedUpdateBy(); ok {
		_spec.AddField(api.FieldUpdateBy, field.TypeUint32, value)
	}
	if auo.mutation.UpdateByCleared() {
		_spec.ClearField(api.FieldUpdateBy, field.TypeUint32)
	}
	if value, ok := auo.mutation.DeletedAt(); ok {
		_spec.SetField(api.FieldDeletedAt, field.TypeTime, value)
	}
	if auo.mutation.DeletedAtCleared() {
		_spec.ClearField(api.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := auo.mutation.DeletedBy(); ok {
		_spec.SetField(api.FieldDeletedBy, field.TypeUint32, value)
	}
	if value, ok := auo.mutation.AddedDeletedBy(); ok {
		_spec.AddField(api.FieldDeletedBy, field.TypeUint32, value)
	}
	if auo.mutation.DeletedByCleared() {
		_spec.ClearField(api.FieldDeletedBy, field.TypeUint32)
	}
	_node = &Api{config: auo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{api.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	auo.mutation.done = true
	return _node, nil
}
