// 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/crowdsecurity/crowdsec/pkg/database/ent/bouncer"
)

// BouncerCreate is the builder for creating a Bouncer entity.
type BouncerCreate struct {
	config
	mutation *BouncerMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (_c *BouncerCreate) SetCreatedAt(v time.Time) *BouncerCreate {
	_c.mutation.SetCreatedAt(v)
	return _c
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableCreatedAt(v *time.Time) *BouncerCreate {
	if v != nil {
		_c.SetCreatedAt(*v)
	}
	return _c
}

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

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableUpdatedAt(v *time.Time) *BouncerCreate {
	if v != nil {
		_c.SetUpdatedAt(*v)
	}
	return _c
}

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

// SetAPIKey sets the "api_key" field.
func (_c *BouncerCreate) SetAPIKey(v string) *BouncerCreate {
	_c.mutation.SetAPIKey(v)
	return _c
}

// SetRevoked sets the "revoked" field.
func (_c *BouncerCreate) SetRevoked(v bool) *BouncerCreate {
	_c.mutation.SetRevoked(v)
	return _c
}

// SetIPAddress sets the "ip_address" field.
func (_c *BouncerCreate) SetIPAddress(v string) *BouncerCreate {
	_c.mutation.SetIPAddress(v)
	return _c
}

// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableIPAddress(v *string) *BouncerCreate {
	if v != nil {
		_c.SetIPAddress(*v)
	}
	return _c
}

// SetType sets the "type" field.
func (_c *BouncerCreate) SetType(v string) *BouncerCreate {
	_c.mutation.SetType(v)
	return _c
}

// SetNillableType sets the "type" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableType(v *string) *BouncerCreate {
	if v != nil {
		_c.SetType(*v)
	}
	return _c
}

// SetVersion sets the "version" field.
func (_c *BouncerCreate) SetVersion(v string) *BouncerCreate {
	_c.mutation.SetVersion(v)
	return _c
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableVersion(v *string) *BouncerCreate {
	if v != nil {
		_c.SetVersion(*v)
	}
	return _c
}

// SetLastPull sets the "last_pull" field.
func (_c *BouncerCreate) SetLastPull(v time.Time) *BouncerCreate {
	_c.mutation.SetLastPull(v)
	return _c
}

// SetNillableLastPull sets the "last_pull" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableLastPull(v *time.Time) *BouncerCreate {
	if v != nil {
		_c.SetLastPull(*v)
	}
	return _c
}

// SetAuthType sets the "auth_type" field.
func (_c *BouncerCreate) SetAuthType(v string) *BouncerCreate {
	_c.mutation.SetAuthType(v)
	return _c
}

// SetNillableAuthType sets the "auth_type" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableAuthType(v *string) *BouncerCreate {
	if v != nil {
		_c.SetAuthType(*v)
	}
	return _c
}

// SetOsname sets the "osname" field.
func (_c *BouncerCreate) SetOsname(v string) *BouncerCreate {
	_c.mutation.SetOsname(v)
	return _c
}

// SetNillableOsname sets the "osname" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableOsname(v *string) *BouncerCreate {
	if v != nil {
		_c.SetOsname(*v)
	}
	return _c
}

// SetOsfamily sets the "osfamily" field.
func (_c *BouncerCreate) SetOsfamily(v string) *BouncerCreate {
	_c.mutation.SetOsfamily(v)
	return _c
}

// SetNillableOsfamily sets the "osfamily" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableOsfamily(v *string) *BouncerCreate {
	if v != nil {
		_c.SetOsfamily(*v)
	}
	return _c
}

// SetOsversion sets the "osversion" field.
func (_c *BouncerCreate) SetOsversion(v string) *BouncerCreate {
	_c.mutation.SetOsversion(v)
	return _c
}

// SetNillableOsversion sets the "osversion" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableOsversion(v *string) *BouncerCreate {
	if v != nil {
		_c.SetOsversion(*v)
	}
	return _c
}

// SetFeatureflags sets the "featureflags" field.
func (_c *BouncerCreate) SetFeatureflags(v string) *BouncerCreate {
	_c.mutation.SetFeatureflags(v)
	return _c
}

// SetNillableFeatureflags sets the "featureflags" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableFeatureflags(v *string) *BouncerCreate {
	if v != nil {
		_c.SetFeatureflags(*v)
	}
	return _c
}

// SetAutoCreated sets the "auto_created" field.
func (_c *BouncerCreate) SetAutoCreated(v bool) *BouncerCreate {
	_c.mutation.SetAutoCreated(v)
	return _c
}

// SetNillableAutoCreated sets the "auto_created" field if the given value is not nil.
func (_c *BouncerCreate) SetNillableAutoCreated(v *bool) *BouncerCreate {
	if v != nil {
		_c.SetAutoCreated(*v)
	}
	return _c
}

// Mutation returns the BouncerMutation object of the builder.
func (_c *BouncerCreate) Mutation() *BouncerMutation {
	return _c.mutation
}

// Save creates the Bouncer in the database.
func (_c *BouncerCreate) Save(ctx context.Context) (*Bouncer, error) {
	_c.defaults()
	return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (_c *BouncerCreate) SaveX(ctx context.Context) *Bouncer {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// defaults sets the default values of the builder before save.
func (_c *BouncerCreate) defaults() {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		v := bouncer.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		v := bouncer.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
	if _, ok := _c.mutation.IPAddress(); !ok {
		v := bouncer.DefaultIPAddress
		_c.mutation.SetIPAddress(v)
	}
	if _, ok := _c.mutation.AuthType(); !ok {
		v := bouncer.DefaultAuthType
		_c.mutation.SetAuthType(v)
	}
	if _, ok := _c.mutation.AutoCreated(); !ok {
		v := bouncer.DefaultAutoCreated
		_c.mutation.SetAutoCreated(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_c *BouncerCreate) check() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Bouncer.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Bouncer.updated_at"`)}
	}
	if _, ok := _c.mutation.Name(); !ok {
		return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Bouncer.name"`)}
	}
	if _, ok := _c.mutation.APIKey(); !ok {
		return &ValidationError{Name: "api_key", err: errors.New(`ent: missing required field "Bouncer.api_key"`)}
	}
	if _, ok := _c.mutation.Revoked(); !ok {
		return &ValidationError{Name: "revoked", err: errors.New(`ent: missing required field "Bouncer.revoked"`)}
	}
	if _, ok := _c.mutation.AuthType(); !ok {
		return &ValidationError{Name: "auth_type", err: errors.New(`ent: missing required field "Bouncer.auth_type"`)}
	}
	if _, ok := _c.mutation.AutoCreated(); !ok {
		return &ValidationError{Name: "auto_created", err: errors.New(`ent: missing required field "Bouncer.auto_created"`)}
	}
	return nil
}

func (_c *BouncerCreate) sqlSave(ctx context.Context) (*Bouncer, error) {
	if err := _c.check(); err != nil {
		return nil, err
	}
	_node, _spec := _c.createSpec()
	if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	id := _spec.ID.Value.(int64)
	_node.ID = int(id)
	_c.mutation.id = &_node.ID
	_c.mutation.done = true
	return _node, nil
}

func (_c *BouncerCreate) createSpec() (*Bouncer, *sqlgraph.CreateSpec) {
	var (
		_node = &Bouncer{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(bouncer.Table, sqlgraph.NewFieldSpec(bouncer.FieldID, field.TypeInt))
	)
	_spec.OnConflict = _c.conflict
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(bouncer.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(bouncer.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := _c.mutation.Name(); ok {
		_spec.SetField(bouncer.FieldName, field.TypeString, value)
		_node.Name = value
	}
	if value, ok := _c.mutation.APIKey(); ok {
		_spec.SetField(bouncer.FieldAPIKey, field.TypeString, value)
		_node.APIKey = value
	}
	if value, ok := _c.mutation.Revoked(); ok {
		_spec.SetField(bouncer.FieldRevoked, field.TypeBool, value)
		_node.Revoked = value
	}
	if value, ok := _c.mutation.IPAddress(); ok {
		_spec.SetField(bouncer.FieldIPAddress, field.TypeString, value)
		_node.IPAddress = value
	}
	if value, ok := _c.mutation.GetType(); ok {
		_spec.SetField(bouncer.FieldType, field.TypeString, value)
		_node.Type = value
	}
	if value, ok := _c.mutation.Version(); ok {
		_spec.SetField(bouncer.FieldVersion, field.TypeString, value)
		_node.Version = value
	}
	if value, ok := _c.mutation.LastPull(); ok {
		_spec.SetField(bouncer.FieldLastPull, field.TypeTime, value)
		_node.LastPull = &value
	}
	if value, ok := _c.mutation.AuthType(); ok {
		_spec.SetField(bouncer.FieldAuthType, field.TypeString, value)
		_node.AuthType = value
	}
	if value, ok := _c.mutation.Osname(); ok {
		_spec.SetField(bouncer.FieldOsname, field.TypeString, value)
		_node.Osname = value
	}
	if value, ok := _c.mutation.Osfamily(); ok {
		_spec.SetField(bouncer.FieldOsfamily, field.TypeString, value)
		_node.Osfamily = value
	}
	if value, ok := _c.mutation.Osversion(); ok {
		_spec.SetField(bouncer.FieldOsversion, field.TypeString, value)
		_node.Osversion = value
	}
	if value, ok := _c.mutation.Featureflags(); ok {
		_spec.SetField(bouncer.FieldFeatureflags, field.TypeString, value)
		_node.Featureflags = value
	}
	if value, ok := _c.mutation.AutoCreated(); ok {
		_spec.SetField(bouncer.FieldAutoCreated, field.TypeBool, value)
		_node.AutoCreated = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Bouncer.Create().
//		SetCreatedAt(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.BouncerUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *BouncerCreate) OnConflict(opts ...sql.ConflictOption) *BouncerUpsertOne {
	_c.conflict = opts
	return &BouncerUpsertOne{
		create: _c,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Bouncer.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (_c *BouncerCreate) OnConflictColumns(columns ...string) *BouncerUpsertOne {
	_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
	return &BouncerUpsertOne{
		create: _c,
	}
}

type (
	// BouncerUpsertOne is the builder for "upsert"-ing
	//  one Bouncer node.
	BouncerUpsertOne struct {
		create *BouncerCreate
	}

	// BouncerUpsert is the "OnConflict" setter.
	BouncerUpsert struct {
		*sql.UpdateSet
	}
)

// SetUpdatedAt sets the "updated_at" field.
func (u *BouncerUpsert) SetUpdatedAt(v time.Time) *BouncerUpsert {
	u.Set(bouncer.FieldUpdatedAt, v)
	return u
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateUpdatedAt() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldUpdatedAt)
	return u
}

// SetAPIKey sets the "api_key" field.
func (u *BouncerUpsert) SetAPIKey(v string) *BouncerUpsert {
	u.Set(bouncer.FieldAPIKey, v)
	return u
}

// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateAPIKey() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldAPIKey)
	return u
}

// SetRevoked sets the "revoked" field.
func (u *BouncerUpsert) SetRevoked(v bool) *BouncerUpsert {
	u.Set(bouncer.FieldRevoked, v)
	return u
}

// UpdateRevoked sets the "revoked" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateRevoked() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldRevoked)
	return u
}

// SetIPAddress sets the "ip_address" field.
func (u *BouncerUpsert) SetIPAddress(v string) *BouncerUpsert {
	u.Set(bouncer.FieldIPAddress, v)
	return u
}

// UpdateIPAddress sets the "ip_address" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateIPAddress() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldIPAddress)
	return u
}

// ClearIPAddress clears the value of the "ip_address" field.
func (u *BouncerUpsert) ClearIPAddress() *BouncerUpsert {
	u.SetNull(bouncer.FieldIPAddress)
	return u
}

// SetType sets the "type" field.
func (u *BouncerUpsert) SetType(v string) *BouncerUpsert {
	u.Set(bouncer.FieldType, v)
	return u
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateType() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldType)
	return u
}

// ClearType clears the value of the "type" field.
func (u *BouncerUpsert) ClearType() *BouncerUpsert {
	u.SetNull(bouncer.FieldType)
	return u
}

// SetVersion sets the "version" field.
func (u *BouncerUpsert) SetVersion(v string) *BouncerUpsert {
	u.Set(bouncer.FieldVersion, v)
	return u
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateVersion() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldVersion)
	return u
}

// ClearVersion clears the value of the "version" field.
func (u *BouncerUpsert) ClearVersion() *BouncerUpsert {
	u.SetNull(bouncer.FieldVersion)
	return u
}

// SetLastPull sets the "last_pull" field.
func (u *BouncerUpsert) SetLastPull(v time.Time) *BouncerUpsert {
	u.Set(bouncer.FieldLastPull, v)
	return u
}

// UpdateLastPull sets the "last_pull" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateLastPull() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldLastPull)
	return u
}

// ClearLastPull clears the value of the "last_pull" field.
func (u *BouncerUpsert) ClearLastPull() *BouncerUpsert {
	u.SetNull(bouncer.FieldLastPull)
	return u
}

// SetAuthType sets the "auth_type" field.
func (u *BouncerUpsert) SetAuthType(v string) *BouncerUpsert {
	u.Set(bouncer.FieldAuthType, v)
	return u
}

// UpdateAuthType sets the "auth_type" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateAuthType() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldAuthType)
	return u
}

// SetOsname sets the "osname" field.
func (u *BouncerUpsert) SetOsname(v string) *BouncerUpsert {
	u.Set(bouncer.FieldOsname, v)
	return u
}

// UpdateOsname sets the "osname" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateOsname() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldOsname)
	return u
}

// ClearOsname clears the value of the "osname" field.
func (u *BouncerUpsert) ClearOsname() *BouncerUpsert {
	u.SetNull(bouncer.FieldOsname)
	return u
}

// SetOsfamily sets the "osfamily" field.
func (u *BouncerUpsert) SetOsfamily(v string) *BouncerUpsert {
	u.Set(bouncer.FieldOsfamily, v)
	return u
}

// UpdateOsfamily sets the "osfamily" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateOsfamily() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldOsfamily)
	return u
}

// ClearOsfamily clears the value of the "osfamily" field.
func (u *BouncerUpsert) ClearOsfamily() *BouncerUpsert {
	u.SetNull(bouncer.FieldOsfamily)
	return u
}

// SetOsversion sets the "osversion" field.
func (u *BouncerUpsert) SetOsversion(v string) *BouncerUpsert {
	u.Set(bouncer.FieldOsversion, v)
	return u
}

// UpdateOsversion sets the "osversion" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateOsversion() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldOsversion)
	return u
}

// ClearOsversion clears the value of the "osversion" field.
func (u *BouncerUpsert) ClearOsversion() *BouncerUpsert {
	u.SetNull(bouncer.FieldOsversion)
	return u
}

// SetFeatureflags sets the "featureflags" field.
func (u *BouncerUpsert) SetFeatureflags(v string) *BouncerUpsert {
	u.Set(bouncer.FieldFeatureflags, v)
	return u
}

// UpdateFeatureflags sets the "featureflags" field to the value that was provided on create.
func (u *BouncerUpsert) UpdateFeatureflags() *BouncerUpsert {
	u.SetExcluded(bouncer.FieldFeatureflags)
	return u
}

// ClearFeatureflags clears the value of the "featureflags" field.
func (u *BouncerUpsert) ClearFeatureflags() *BouncerUpsert {
	u.SetNull(bouncer.FieldFeatureflags)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
//	client.Bouncer.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *BouncerUpsertOne) UpdateNewValues() *BouncerUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(bouncer.FieldCreatedAt)
		}
		if _, exists := u.create.mutation.Name(); exists {
			s.SetIgnore(bouncer.FieldName)
		}
		if _, exists := u.create.mutation.AutoCreated(); exists {
			s.SetIgnore(bouncer.FieldAutoCreated)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Bouncer.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *BouncerUpsertOne) Ignore() *BouncerUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *BouncerUpsertOne) DoNothing() *BouncerUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the BouncerCreate.OnConflict
// documentation for more info.
func (u *BouncerUpsertOne) Update(set func(*BouncerUpsert)) *BouncerUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&BouncerUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *BouncerUpsertOne) SetUpdatedAt(v time.Time) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateUpdatedAt() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetAPIKey sets the "api_key" field.
func (u *BouncerUpsertOne) SetAPIKey(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetAPIKey(v)
	})
}

// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateAPIKey() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateAPIKey()
	})
}

// SetRevoked sets the "revoked" field.
func (u *BouncerUpsertOne) SetRevoked(v bool) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetRevoked(v)
	})
}

// UpdateRevoked sets the "revoked" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateRevoked() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateRevoked()
	})
}

// SetIPAddress sets the "ip_address" field.
func (u *BouncerUpsertOne) SetIPAddress(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetIPAddress(v)
	})
}

// UpdateIPAddress sets the "ip_address" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateIPAddress() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateIPAddress()
	})
}

// ClearIPAddress clears the value of the "ip_address" field.
func (u *BouncerUpsertOne) ClearIPAddress() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearIPAddress()
	})
}

// SetType sets the "type" field.
func (u *BouncerUpsertOne) SetType(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateType() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateType()
	})
}

// ClearType clears the value of the "type" field.
func (u *BouncerUpsertOne) ClearType() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearType()
	})
}

// SetVersion sets the "version" field.
func (u *BouncerUpsertOne) SetVersion(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetVersion(v)
	})
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateVersion() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateVersion()
	})
}

// ClearVersion clears the value of the "version" field.
func (u *BouncerUpsertOne) ClearVersion() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearVersion()
	})
}

// SetLastPull sets the "last_pull" field.
func (u *BouncerUpsertOne) SetLastPull(v time.Time) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetLastPull(v)
	})
}

// UpdateLastPull sets the "last_pull" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateLastPull() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateLastPull()
	})
}

// ClearLastPull clears the value of the "last_pull" field.
func (u *BouncerUpsertOne) ClearLastPull() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearLastPull()
	})
}

// SetAuthType sets the "auth_type" field.
func (u *BouncerUpsertOne) SetAuthType(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetAuthType(v)
	})
}

// UpdateAuthType sets the "auth_type" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateAuthType() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateAuthType()
	})
}

// SetOsname sets the "osname" field.
func (u *BouncerUpsertOne) SetOsname(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetOsname(v)
	})
}

// UpdateOsname sets the "osname" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateOsname() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateOsname()
	})
}

// ClearOsname clears the value of the "osname" field.
func (u *BouncerUpsertOne) ClearOsname() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearOsname()
	})
}

// SetOsfamily sets the "osfamily" field.
func (u *BouncerUpsertOne) SetOsfamily(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetOsfamily(v)
	})
}

// UpdateOsfamily sets the "osfamily" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateOsfamily() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateOsfamily()
	})
}

// ClearOsfamily clears the value of the "osfamily" field.
func (u *BouncerUpsertOne) ClearOsfamily() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearOsfamily()
	})
}

// SetOsversion sets the "osversion" field.
func (u *BouncerUpsertOne) SetOsversion(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetOsversion(v)
	})
}

// UpdateOsversion sets the "osversion" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateOsversion() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateOsversion()
	})
}

// ClearOsversion clears the value of the "osversion" field.
func (u *BouncerUpsertOne) ClearOsversion() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearOsversion()
	})
}

// SetFeatureflags sets the "featureflags" field.
func (u *BouncerUpsertOne) SetFeatureflags(v string) *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.SetFeatureflags(v)
	})
}

// UpdateFeatureflags sets the "featureflags" field to the value that was provided on create.
func (u *BouncerUpsertOne) UpdateFeatureflags() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateFeatureflags()
	})
}

// ClearFeatureflags clears the value of the "featureflags" field.
func (u *BouncerUpsertOne) ClearFeatureflags() *BouncerUpsertOne {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearFeatureflags()
	})
}

// Exec executes the query.
func (u *BouncerUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for BouncerCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

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

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *BouncerUpsertOne) ID(ctx context.Context) (id int, err error) {
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *BouncerUpsertOne) IDX(ctx context.Context) int {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// BouncerCreateBulk is the builder for creating many Bouncer entities in bulk.
type BouncerCreateBulk struct {
	config
	err      error
	builders []*BouncerCreate
	conflict []sql.ConflictOption
}

// Save creates the Bouncer entities in the database.
func (_c *BouncerCreateBulk) Save(ctx context.Context) ([]*Bouncer, error) {
	if _c.err != nil {
		return nil, _c.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
	nodes := make([]*Bouncer, len(_c.builders))
	mutators := make([]Mutator, len(_c.builders))
	for i := range _c.builders {
		func(i int, root context.Context) {
			builder := _c.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*BouncerMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = _c.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = int(id)
				}
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (_c *BouncerCreateBulk) SaveX(ctx context.Context) []*Bouncer {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Bouncer.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.BouncerUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *BouncerCreateBulk) OnConflict(opts ...sql.ConflictOption) *BouncerUpsertBulk {
	_c.conflict = opts
	return &BouncerUpsertBulk{
		create: _c,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Bouncer.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (_c *BouncerCreateBulk) OnConflictColumns(columns ...string) *BouncerUpsertBulk {
	_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
	return &BouncerUpsertBulk{
		create: _c,
	}
}

// BouncerUpsertBulk is the builder for "upsert"-ing
// a bulk of Bouncer nodes.
type BouncerUpsertBulk struct {
	create *BouncerCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.Bouncer.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *BouncerUpsertBulk) UpdateNewValues() *BouncerUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(bouncer.FieldCreatedAt)
			}
			if _, exists := b.mutation.Name(); exists {
				s.SetIgnore(bouncer.FieldName)
			}
			if _, exists := b.mutation.AutoCreated(); exists {
				s.SetIgnore(bouncer.FieldAutoCreated)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Bouncer.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *BouncerUpsertBulk) Ignore() *BouncerUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *BouncerUpsertBulk) DoNothing() *BouncerUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the BouncerCreateBulk.OnConflict
// documentation for more info.
func (u *BouncerUpsertBulk) Update(set func(*BouncerUpsert)) *BouncerUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&BouncerUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *BouncerUpsertBulk) SetUpdatedAt(v time.Time) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateUpdatedAt() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetAPIKey sets the "api_key" field.
func (u *BouncerUpsertBulk) SetAPIKey(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetAPIKey(v)
	})
}

// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateAPIKey() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateAPIKey()
	})
}

// SetRevoked sets the "revoked" field.
func (u *BouncerUpsertBulk) SetRevoked(v bool) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetRevoked(v)
	})
}

// UpdateRevoked sets the "revoked" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateRevoked() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateRevoked()
	})
}

// SetIPAddress sets the "ip_address" field.
func (u *BouncerUpsertBulk) SetIPAddress(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetIPAddress(v)
	})
}

// UpdateIPAddress sets the "ip_address" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateIPAddress() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateIPAddress()
	})
}

// ClearIPAddress clears the value of the "ip_address" field.
func (u *BouncerUpsertBulk) ClearIPAddress() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearIPAddress()
	})
}

// SetType sets the "type" field.
func (u *BouncerUpsertBulk) SetType(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateType() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateType()
	})
}

// ClearType clears the value of the "type" field.
func (u *BouncerUpsertBulk) ClearType() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearType()
	})
}

// SetVersion sets the "version" field.
func (u *BouncerUpsertBulk) SetVersion(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetVersion(v)
	})
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateVersion() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateVersion()
	})
}

// ClearVersion clears the value of the "version" field.
func (u *BouncerUpsertBulk) ClearVersion() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearVersion()
	})
}

// SetLastPull sets the "last_pull" field.
func (u *BouncerUpsertBulk) SetLastPull(v time.Time) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetLastPull(v)
	})
}

// UpdateLastPull sets the "last_pull" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateLastPull() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateLastPull()
	})
}

// ClearLastPull clears the value of the "last_pull" field.
func (u *BouncerUpsertBulk) ClearLastPull() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearLastPull()
	})
}

// SetAuthType sets the "auth_type" field.
func (u *BouncerUpsertBulk) SetAuthType(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetAuthType(v)
	})
}

// UpdateAuthType sets the "auth_type" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateAuthType() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateAuthType()
	})
}

// SetOsname sets the "osname" field.
func (u *BouncerUpsertBulk) SetOsname(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetOsname(v)
	})
}

// UpdateOsname sets the "osname" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateOsname() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateOsname()
	})
}

// ClearOsname clears the value of the "osname" field.
func (u *BouncerUpsertBulk) ClearOsname() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearOsname()
	})
}

// SetOsfamily sets the "osfamily" field.
func (u *BouncerUpsertBulk) SetOsfamily(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetOsfamily(v)
	})
}

// UpdateOsfamily sets the "osfamily" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateOsfamily() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateOsfamily()
	})
}

// ClearOsfamily clears the value of the "osfamily" field.
func (u *BouncerUpsertBulk) ClearOsfamily() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearOsfamily()
	})
}

// SetOsversion sets the "osversion" field.
func (u *BouncerUpsertBulk) SetOsversion(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetOsversion(v)
	})
}

// UpdateOsversion sets the "osversion" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateOsversion() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateOsversion()
	})
}

// ClearOsversion clears the value of the "osversion" field.
func (u *BouncerUpsertBulk) ClearOsversion() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearOsversion()
	})
}

// SetFeatureflags sets the "featureflags" field.
func (u *BouncerUpsertBulk) SetFeatureflags(v string) *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.SetFeatureflags(v)
	})
}

// UpdateFeatureflags sets the "featureflags" field to the value that was provided on create.
func (u *BouncerUpsertBulk) UpdateFeatureflags() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.UpdateFeatureflags()
	})
}

// ClearFeatureflags clears the value of the "featureflags" field.
func (u *BouncerUpsertBulk) ClearFeatureflags() *BouncerUpsertBulk {
	return u.Update(func(s *BouncerUpsert) {
		s.ClearFeatureflags()
	})
}

// Exec executes the query.
func (u *BouncerUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the BouncerCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for BouncerCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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