// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/Wei-Shaw/sub2api/ent/requestcapturelog"
)

// RequestCaptureLogCreate is the builder for creating a RequestCaptureLog entity.
type RequestCaptureLogCreate struct {
	config
	mutation *RequestCaptureLogMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetAPIKeyID sets the "api_key_id" field.
func (_c *RequestCaptureLogCreate) SetAPIKeyID(v int64) *RequestCaptureLogCreate {
	_c.mutation.SetAPIKeyID(v)
	return _c
}

// SetUserID sets the "user_id" field.
func (_c *RequestCaptureLogCreate) SetUserID(v int64) *RequestCaptureLogCreate {
	_c.mutation.SetUserID(v)
	return _c
}

// SetRequestID sets the "request_id" field.
func (_c *RequestCaptureLogCreate) SetRequestID(v string) *RequestCaptureLogCreate {
	_c.mutation.SetRequestID(v)
	return _c
}

// SetNillableRequestID sets the "request_id" field if the given value is not nil.
func (_c *RequestCaptureLogCreate) SetNillableRequestID(v *string) *RequestCaptureLogCreate {
	if v != nil {
		_c.SetRequestID(*v)
	}
	return _c
}

// SetPath sets the "path" field.
func (_c *RequestCaptureLogCreate) SetPath(v string) *RequestCaptureLogCreate {
	_c.mutation.SetPath(v)
	return _c
}

// SetNillablePath sets the "path" field if the given value is not nil.
func (_c *RequestCaptureLogCreate) SetNillablePath(v *string) *RequestCaptureLogCreate {
	if v != nil {
		_c.SetPath(*v)
	}
	return _c
}

// SetMethod sets the "method" field.
func (_c *RequestCaptureLogCreate) SetMethod(v string) *RequestCaptureLogCreate {
	_c.mutation.SetMethod(v)
	return _c
}

// SetNillableMethod sets the "method" field if the given value is not nil.
func (_c *RequestCaptureLogCreate) SetNillableMethod(v *string) *RequestCaptureLogCreate {
	if v != nil {
		_c.SetMethod(*v)
	}
	return _c
}

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

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

// SetRequestBody sets the "request_body" field.
func (_c *RequestCaptureLogCreate) SetRequestBody(v string) *RequestCaptureLogCreate {
	_c.mutation.SetRequestBody(v)
	return _c
}

// SetNillableRequestBody sets the "request_body" field if the given value is not nil.
func (_c *RequestCaptureLogCreate) SetNillableRequestBody(v *string) *RequestCaptureLogCreate {
	if v != nil {
		_c.SetRequestBody(*v)
	}
	return _c
}

// SetResponseBody sets the "response_body" field.
func (_c *RequestCaptureLogCreate) SetResponseBody(v string) *RequestCaptureLogCreate {
	_c.mutation.SetResponseBody(v)
	return _c
}

// SetNillableResponseBody sets the "response_body" field if the given value is not nil.
func (_c *RequestCaptureLogCreate) SetNillableResponseBody(v *string) *RequestCaptureLogCreate {
	if v != nil {
		_c.SetResponseBody(*v)
	}
	return _c
}

// SetNfsFilePath sets the "nfs_file_path" field.
func (_c *RequestCaptureLogCreate) SetNfsFilePath(v string) *RequestCaptureLogCreate {
	_c.mutation.SetNfsFilePath(v)
	return _c
}

// SetNillableNfsFilePath sets the "nfs_file_path" field if the given value is not nil.
func (_c *RequestCaptureLogCreate) SetNillableNfsFilePath(v *string) *RequestCaptureLogCreate {
	if v != nil {
		_c.SetNfsFilePath(*v)
	}
	return _c
}

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

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

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

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

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *RequestCaptureLogCreate) 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 *RequestCaptureLogCreate) defaults() {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		v := requestcapturelog.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_c *RequestCaptureLogCreate) check() error {
	if _, ok := _c.mutation.APIKeyID(); !ok {
		return &ValidationError{Name: "api_key_id", err: errors.New(`ent: missing required field "RequestCaptureLog.api_key_id"`)}
	}
	if _, ok := _c.mutation.UserID(); !ok {
		return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "RequestCaptureLog.user_id"`)}
	}
	if v, ok := _c.mutation.RequestID(); ok {
		if err := requestcapturelog.RequestIDValidator(v); err != nil {
			return &ValidationError{Name: "request_id", err: fmt.Errorf(`ent: validator failed for field "RequestCaptureLog.request_id": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Path(); ok {
		if err := requestcapturelog.PathValidator(v); err != nil {
			return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "RequestCaptureLog.path": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Method(); ok {
		if err := requestcapturelog.MethodValidator(v); err != nil {
			return &ValidationError{Name: "method", err: fmt.Errorf(`ent: validator failed for field "RequestCaptureLog.method": %w`, err)}
		}
	}
	if v, ok := _c.mutation.IPAddress(); ok {
		if err := requestcapturelog.IPAddressValidator(v); err != nil {
			return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "RequestCaptureLog.ip_address": %w`, err)}
		}
	}
	if v, ok := _c.mutation.NfsFilePath(); ok {
		if err := requestcapturelog.NfsFilePathValidator(v); err != nil {
			return &ValidationError{Name: "nfs_file_path", err: fmt.Errorf(`ent: validator failed for field "RequestCaptureLog.nfs_file_path": %w`, err)}
		}
	}
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RequestCaptureLog.created_at"`)}
	}
	return nil
}

func (_c *RequestCaptureLogCreate) sqlSave(ctx context.Context) (*RequestCaptureLog, 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 = int64(id)
	_c.mutation.id = &_node.ID
	_c.mutation.done = true
	return _node, nil
}

func (_c *RequestCaptureLogCreate) createSpec() (*RequestCaptureLog, *sqlgraph.CreateSpec) {
	var (
		_node = &RequestCaptureLog{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(requestcapturelog.Table, sqlgraph.NewFieldSpec(requestcapturelog.FieldID, field.TypeInt64))
	)
	_spec.OnConflict = _c.conflict
	if value, ok := _c.mutation.APIKeyID(); ok {
		_spec.SetField(requestcapturelog.FieldAPIKeyID, field.TypeInt64, value)
		_node.APIKeyID = value
	}
	if value, ok := _c.mutation.UserID(); ok {
		_spec.SetField(requestcapturelog.FieldUserID, field.TypeInt64, value)
		_node.UserID = value
	}
	if value, ok := _c.mutation.RequestID(); ok {
		_spec.SetField(requestcapturelog.FieldRequestID, field.TypeString, value)
		_node.RequestID = &value
	}
	if value, ok := _c.mutation.Path(); ok {
		_spec.SetField(requestcapturelog.FieldPath, field.TypeString, value)
		_node.Path = &value
	}
	if value, ok := _c.mutation.Method(); ok {
		_spec.SetField(requestcapturelog.FieldMethod, field.TypeString, value)
		_node.Method = &value
	}
	if value, ok := _c.mutation.IPAddress(); ok {
		_spec.SetField(requestcapturelog.FieldIPAddress, field.TypeString, value)
		_node.IPAddress = &value
	}
	if value, ok := _c.mutation.RequestBody(); ok {
		_spec.SetField(requestcapturelog.FieldRequestBody, field.TypeString, value)
		_node.RequestBody = &value
	}
	if value, ok := _c.mutation.ResponseBody(); ok {
		_spec.SetField(requestcapturelog.FieldResponseBody, field.TypeString, value)
		_node.ResponseBody = &value
	}
	if value, ok := _c.mutation.NfsFilePath(); ok {
		_spec.SetField(requestcapturelog.FieldNfsFilePath, field.TypeString, value)
		_node.NfsFilePath = &value
	}
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(requestcapturelog.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.RequestCaptureLog.Create().
//		SetAPIKeyID(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.RequestCaptureLogUpsert) {
//			SetAPIKeyID(v+v).
//		}).
//		Exec(ctx)
func (_c *RequestCaptureLogCreate) OnConflict(opts ...sql.ConflictOption) *RequestCaptureLogUpsertOne {
	_c.conflict = opts
	return &RequestCaptureLogUpsertOne{
		create: _c,
	}
}

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

type (
	// RequestCaptureLogUpsertOne is the builder for "upsert"-ing
	//  one RequestCaptureLog node.
	RequestCaptureLogUpsertOne struct {
		create *RequestCaptureLogCreate
	}

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

// SetAPIKeyID sets the "api_key_id" field.
func (u *RequestCaptureLogUpsert) SetAPIKeyID(v int64) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldAPIKeyID, v)
	return u
}

// UpdateAPIKeyID sets the "api_key_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateAPIKeyID() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldAPIKeyID)
	return u
}

// AddAPIKeyID adds v to the "api_key_id" field.
func (u *RequestCaptureLogUpsert) AddAPIKeyID(v int64) *RequestCaptureLogUpsert {
	u.Add(requestcapturelog.FieldAPIKeyID, v)
	return u
}

// SetUserID sets the "user_id" field.
func (u *RequestCaptureLogUpsert) SetUserID(v int64) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldUserID, v)
	return u
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateUserID() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldUserID)
	return u
}

// AddUserID adds v to the "user_id" field.
func (u *RequestCaptureLogUpsert) AddUserID(v int64) *RequestCaptureLogUpsert {
	u.Add(requestcapturelog.FieldUserID, v)
	return u
}

// SetRequestID sets the "request_id" field.
func (u *RequestCaptureLogUpsert) SetRequestID(v string) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldRequestID, v)
	return u
}

// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateRequestID() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldRequestID)
	return u
}

// ClearRequestID clears the value of the "request_id" field.
func (u *RequestCaptureLogUpsert) ClearRequestID() *RequestCaptureLogUpsert {
	u.SetNull(requestcapturelog.FieldRequestID)
	return u
}

// SetPath sets the "path" field.
func (u *RequestCaptureLogUpsert) SetPath(v string) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldPath, v)
	return u
}

// UpdatePath sets the "path" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdatePath() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldPath)
	return u
}

// ClearPath clears the value of the "path" field.
func (u *RequestCaptureLogUpsert) ClearPath() *RequestCaptureLogUpsert {
	u.SetNull(requestcapturelog.FieldPath)
	return u
}

// SetMethod sets the "method" field.
func (u *RequestCaptureLogUpsert) SetMethod(v string) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldMethod, v)
	return u
}

// UpdateMethod sets the "method" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateMethod() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldMethod)
	return u
}

// ClearMethod clears the value of the "method" field.
func (u *RequestCaptureLogUpsert) ClearMethod() *RequestCaptureLogUpsert {
	u.SetNull(requestcapturelog.FieldMethod)
	return u
}

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

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

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

// SetRequestBody sets the "request_body" field.
func (u *RequestCaptureLogUpsert) SetRequestBody(v string) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldRequestBody, v)
	return u
}

// UpdateRequestBody sets the "request_body" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateRequestBody() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldRequestBody)
	return u
}

// ClearRequestBody clears the value of the "request_body" field.
func (u *RequestCaptureLogUpsert) ClearRequestBody() *RequestCaptureLogUpsert {
	u.SetNull(requestcapturelog.FieldRequestBody)
	return u
}

// SetResponseBody sets the "response_body" field.
func (u *RequestCaptureLogUpsert) SetResponseBody(v string) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldResponseBody, v)
	return u
}

// UpdateResponseBody sets the "response_body" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateResponseBody() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldResponseBody)
	return u
}

// ClearResponseBody clears the value of the "response_body" field.
func (u *RequestCaptureLogUpsert) ClearResponseBody() *RequestCaptureLogUpsert {
	u.SetNull(requestcapturelog.FieldResponseBody)
	return u
}

// SetNfsFilePath sets the "nfs_file_path" field.
func (u *RequestCaptureLogUpsert) SetNfsFilePath(v string) *RequestCaptureLogUpsert {
	u.Set(requestcapturelog.FieldNfsFilePath, v)
	return u
}

// UpdateNfsFilePath sets the "nfs_file_path" field to the value that was provided on create.
func (u *RequestCaptureLogUpsert) UpdateNfsFilePath() *RequestCaptureLogUpsert {
	u.SetExcluded(requestcapturelog.FieldNfsFilePath)
	return u
}

// ClearNfsFilePath clears the value of the "nfs_file_path" field.
func (u *RequestCaptureLogUpsert) ClearNfsFilePath() *RequestCaptureLogUpsert {
	u.SetNull(requestcapturelog.FieldNfsFilePath)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
//	client.RequestCaptureLog.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *RequestCaptureLogUpsertOne) UpdateNewValues() *RequestCaptureLogUpsertOne {
	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(requestcapturelog.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.RequestCaptureLog.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *RequestCaptureLogUpsertOne) Ignore() *RequestCaptureLogUpsertOne {
	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 *RequestCaptureLogUpsertOne) DoNothing() *RequestCaptureLogUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

// SetAPIKeyID sets the "api_key_id" field.
func (u *RequestCaptureLogUpsertOne) SetAPIKeyID(v int64) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetAPIKeyID(v)
	})
}

// AddAPIKeyID adds v to the "api_key_id" field.
func (u *RequestCaptureLogUpsertOne) AddAPIKeyID(v int64) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.AddAPIKeyID(v)
	})
}

// UpdateAPIKeyID sets the "api_key_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateAPIKeyID() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateAPIKeyID()
	})
}

// SetUserID sets the "user_id" field.
func (u *RequestCaptureLogUpsertOne) SetUserID(v int64) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetUserID(v)
	})
}

// AddUserID adds v to the "user_id" field.
func (u *RequestCaptureLogUpsertOne) AddUserID(v int64) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.AddUserID(v)
	})
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateUserID() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateUserID()
	})
}

// SetRequestID sets the "request_id" field.
func (u *RequestCaptureLogUpsertOne) SetRequestID(v string) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetRequestID(v)
	})
}

// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateRequestID() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateRequestID()
	})
}

// ClearRequestID clears the value of the "request_id" field.
func (u *RequestCaptureLogUpsertOne) ClearRequestID() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearRequestID()
	})
}

// SetPath sets the "path" field.
func (u *RequestCaptureLogUpsertOne) SetPath(v string) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetPath(v)
	})
}

// UpdatePath sets the "path" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdatePath() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdatePath()
	})
}

// ClearPath clears the value of the "path" field.
func (u *RequestCaptureLogUpsertOne) ClearPath() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearPath()
	})
}

// SetMethod sets the "method" field.
func (u *RequestCaptureLogUpsertOne) SetMethod(v string) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetMethod(v)
	})
}

// UpdateMethod sets the "method" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateMethod() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateMethod()
	})
}

// ClearMethod clears the value of the "method" field.
func (u *RequestCaptureLogUpsertOne) ClearMethod() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearMethod()
	})
}

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

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

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

// SetRequestBody sets the "request_body" field.
func (u *RequestCaptureLogUpsertOne) SetRequestBody(v string) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetRequestBody(v)
	})
}

// UpdateRequestBody sets the "request_body" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateRequestBody() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateRequestBody()
	})
}

// ClearRequestBody clears the value of the "request_body" field.
func (u *RequestCaptureLogUpsertOne) ClearRequestBody() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearRequestBody()
	})
}

// SetResponseBody sets the "response_body" field.
func (u *RequestCaptureLogUpsertOne) SetResponseBody(v string) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetResponseBody(v)
	})
}

// UpdateResponseBody sets the "response_body" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateResponseBody() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateResponseBody()
	})
}

// ClearResponseBody clears the value of the "response_body" field.
func (u *RequestCaptureLogUpsertOne) ClearResponseBody() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearResponseBody()
	})
}

// SetNfsFilePath sets the "nfs_file_path" field.
func (u *RequestCaptureLogUpsertOne) SetNfsFilePath(v string) *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetNfsFilePath(v)
	})
}

// UpdateNfsFilePath sets the "nfs_file_path" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertOne) UpdateNfsFilePath() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateNfsFilePath()
	})
}

// ClearNfsFilePath clears the value of the "nfs_file_path" field.
func (u *RequestCaptureLogUpsertOne) ClearNfsFilePath() *RequestCaptureLogUpsertOne {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearNfsFilePath()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *RequestCaptureLogUpsertOne) 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 *RequestCaptureLogUpsertOne) ID(ctx context.Context) (id int64, 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 *RequestCaptureLogUpsertOne) IDX(ctx context.Context) int64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

// Save creates the RequestCaptureLog entities in the database.
func (_c *RequestCaptureLogCreateBulk) Save(ctx context.Context) ([]*RequestCaptureLog, error) {
	if _c.err != nil {
		return nil, _c.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
	nodes := make([]*RequestCaptureLog, 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.(*RequestCaptureLogMutation)
				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 = int64(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 *RequestCaptureLogCreateBulk) SaveX(ctx context.Context) []*RequestCaptureLog {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *RequestCaptureLogCreateBulk) 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.RequestCaptureLog.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.RequestCaptureLogUpsert) {
//			SetAPIKeyID(v+v).
//		}).
//		Exec(ctx)
func (_c *RequestCaptureLogCreateBulk) OnConflict(opts ...sql.ConflictOption) *RequestCaptureLogUpsertBulk {
	_c.conflict = opts
	return &RequestCaptureLogUpsertBulk{
		create: _c,
	}
}

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

// RequestCaptureLogUpsertBulk is the builder for "upsert"-ing
// a bulk of RequestCaptureLog nodes.
type RequestCaptureLogUpsertBulk struct {
	create *RequestCaptureLogCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.RequestCaptureLog.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *RequestCaptureLogUpsertBulk) UpdateNewValues() *RequestCaptureLogUpsertBulk {
	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(requestcapturelog.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.RequestCaptureLog.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *RequestCaptureLogUpsertBulk) Ignore() *RequestCaptureLogUpsertBulk {
	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 *RequestCaptureLogUpsertBulk) DoNothing() *RequestCaptureLogUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

// SetAPIKeyID sets the "api_key_id" field.
func (u *RequestCaptureLogUpsertBulk) SetAPIKeyID(v int64) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetAPIKeyID(v)
	})
}

// AddAPIKeyID adds v to the "api_key_id" field.
func (u *RequestCaptureLogUpsertBulk) AddAPIKeyID(v int64) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.AddAPIKeyID(v)
	})
}

// UpdateAPIKeyID sets the "api_key_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateAPIKeyID() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateAPIKeyID()
	})
}

// SetUserID sets the "user_id" field.
func (u *RequestCaptureLogUpsertBulk) SetUserID(v int64) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetUserID(v)
	})
}

// AddUserID adds v to the "user_id" field.
func (u *RequestCaptureLogUpsertBulk) AddUserID(v int64) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.AddUserID(v)
	})
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateUserID() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateUserID()
	})
}

// SetRequestID sets the "request_id" field.
func (u *RequestCaptureLogUpsertBulk) SetRequestID(v string) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetRequestID(v)
	})
}

// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateRequestID() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateRequestID()
	})
}

// ClearRequestID clears the value of the "request_id" field.
func (u *RequestCaptureLogUpsertBulk) ClearRequestID() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearRequestID()
	})
}

// SetPath sets the "path" field.
func (u *RequestCaptureLogUpsertBulk) SetPath(v string) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetPath(v)
	})
}

// UpdatePath sets the "path" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdatePath() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdatePath()
	})
}

// ClearPath clears the value of the "path" field.
func (u *RequestCaptureLogUpsertBulk) ClearPath() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearPath()
	})
}

// SetMethod sets the "method" field.
func (u *RequestCaptureLogUpsertBulk) SetMethod(v string) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetMethod(v)
	})
}

// UpdateMethod sets the "method" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateMethod() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateMethod()
	})
}

// ClearMethod clears the value of the "method" field.
func (u *RequestCaptureLogUpsertBulk) ClearMethod() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearMethod()
	})
}

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

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

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

// SetRequestBody sets the "request_body" field.
func (u *RequestCaptureLogUpsertBulk) SetRequestBody(v string) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetRequestBody(v)
	})
}

// UpdateRequestBody sets the "request_body" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateRequestBody() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateRequestBody()
	})
}

// ClearRequestBody clears the value of the "request_body" field.
func (u *RequestCaptureLogUpsertBulk) ClearRequestBody() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearRequestBody()
	})
}

// SetResponseBody sets the "response_body" field.
func (u *RequestCaptureLogUpsertBulk) SetResponseBody(v string) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetResponseBody(v)
	})
}

// UpdateResponseBody sets the "response_body" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateResponseBody() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateResponseBody()
	})
}

// ClearResponseBody clears the value of the "response_body" field.
func (u *RequestCaptureLogUpsertBulk) ClearResponseBody() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearResponseBody()
	})
}

// SetNfsFilePath sets the "nfs_file_path" field.
func (u *RequestCaptureLogUpsertBulk) SetNfsFilePath(v string) *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.SetNfsFilePath(v)
	})
}

// UpdateNfsFilePath sets the "nfs_file_path" field to the value that was provided on create.
func (u *RequestCaptureLogUpsertBulk) UpdateNfsFilePath() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.UpdateNfsFilePath()
	})
}

// ClearNfsFilePath clears the value of the "nfs_file_path" field.
func (u *RequestCaptureLogUpsertBulk) ClearNfsFilePath() *RequestCaptureLogUpsertBulk {
	return u.Update(func(s *RequestCaptureLogUpsert) {
		s.ClearNfsFilePath()
	})
}

// Exec executes the query.
func (u *RequestCaptureLogUpsertBulk) 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 RequestCaptureLogCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for RequestCaptureLogCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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