// Code generated by entc, 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/pingcap/test-infra/common/model"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/testbedinfo"
)

// TestbedInfoCreate is the builder for creating a TestbedInfo entity.
type TestbedInfoCreate struct {
	config
	mutation *TestbedInfoMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "createdAt" field.
func (tic *TestbedInfoCreate) SetCreatedAt(t time.Time) *TestbedInfoCreate {
	tic.mutation.SetCreatedAt(t)
	return tic
}

// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableCreatedAt(t *time.Time) *TestbedInfoCreate {
	if t != nil {
		tic.SetCreatedAt(*t)
	}
	return tic
}

// SetUpdatedAt sets the "updatedAt" field.
func (tic *TestbedInfoCreate) SetUpdatedAt(t time.Time) *TestbedInfoCreate {
	tic.mutation.SetUpdatedAt(t)
	return tic
}

// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableUpdatedAt(t *time.Time) *TestbedInfoCreate {
	if t != nil {
		tic.SetUpdatedAt(*t)
	}
	return tic
}

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

// SetStatus sets the "status" field.
func (tic *TestbedInfoCreate) SetStatus(mbis model.TestBedInfoStatus) *TestbedInfoCreate {
	tic.mutation.SetStatus(mbis)
	return tic
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableStatus(mbis *model.TestBedInfoStatus) *TestbedInfoCreate {
	if mbis != nil {
		tic.SetStatus(*mbis)
	}
	return tic
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (tic *TestbedInfoCreate) SetPlanExecutionID(m model.ID) *TestbedInfoCreate {
	tic.mutation.SetPlanExecutionID(m)
	return tic
}

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

// SetNillableURL sets the "url" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableURL(s *string) *TestbedInfoCreate {
	if s != nil {
		tic.SetURL(*s)
	}
	return tic
}

// SetLeaseDDL sets the "leaseDDL" field.
func (tic *TestbedInfoCreate) SetLeaseDDL(t time.Time) *TestbedInfoCreate {
	tic.mutation.SetLeaseDDL(t)
	return tic
}

// SetNillableLeaseDDL sets the "leaseDDL" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableLeaseDDL(t *time.Time) *TestbedInfoCreate {
	if t != nil {
		tic.SetLeaseDDL(*t)
	}
	return tic
}

// SetInitiatedAt sets the "initiatedAt" field.
func (tic *TestbedInfoCreate) SetInitiatedAt(t time.Time) *TestbedInfoCreate {
	tic.mutation.SetInitiatedAt(t)
	return tic
}

// SetNillableInitiatedAt sets the "initiatedAt" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableInitiatedAt(t *time.Time) *TestbedInfoCreate {
	if t != nil {
		tic.SetInitiatedAt(*t)
	}
	return tic
}

// SetReleasedAt sets the "releasedAt" field.
func (tic *TestbedInfoCreate) SetReleasedAt(t time.Time) *TestbedInfoCreate {
	tic.mutation.SetReleasedAt(t)
	return tic
}

// SetNillableReleasedAt sets the "releasedAt" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableReleasedAt(t *time.Time) *TestbedInfoCreate {
	if t != nil {
		tic.SetReleasedAt(*t)
	}
	return tic
}

// SetReleasedBy sets the "releasedBy" field.
func (tic *TestbedInfoCreate) SetReleasedBy(m model.ID) *TestbedInfoCreate {
	tic.mutation.SetReleasedBy(m)
	return tic
}

// SetNillableReleasedBy sets the "releasedBy" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableReleasedBy(m *model.ID) *TestbedInfoCreate {
	if m != nil {
		tic.SetReleasedBy(*m)
	}
	return tic
}

// SetPhysicalResourceRequest sets the "physicalResourceRequest" field.
func (tic *TestbedInfoCreate) SetPhysicalResourceRequest(mr model.PhysicalResource) *TestbedInfoCreate {
	tic.mutation.SetPhysicalResourceRequest(mr)
	return tic
}

// SetNillablePhysicalResourceRequest sets the "physicalResourceRequest" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillablePhysicalResourceRequest(mr *model.PhysicalResource) *TestbedInfoCreate {
	if mr != nil {
		tic.SetPhysicalResourceRequest(*mr)
	}
	return tic
}

// SetResourceItems sets the "resourceItems" field.
func (tic *TestbedInfoCreate) SetResourceItems(mbiri []model.TestBedInfoResourceItem) *TestbedInfoCreate {
	tic.mutation.SetResourceItems(mbiri)
	return tic
}

// SetType sets the "type" field.
func (tic *TestbedInfoCreate) SetType(mbit model.TestBedInfoType) *TestbedInfoCreate {
	tic.mutation.SetType(mbit)
	return tic
}

// SetNillableType sets the "type" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableType(mbit *model.TestBedInfoType) *TestbedInfoCreate {
	if mbit != nil {
		tic.SetType(*mbit)
	}
	return tic
}

// SetSetUpLogURL sets the "setUpLogURL" field.
func (tic *TestbedInfoCreate) SetSetUpLogURL(s string) *TestbedInfoCreate {
	tic.mutation.SetSetUpLogURL(s)
	return tic
}

// SetNillableSetUpLogURL sets the "setUpLogURL" field if the given value is not nil.
func (tic *TestbedInfoCreate) SetNillableSetUpLogURL(s *string) *TestbedInfoCreate {
	if s != nil {
		tic.SetSetUpLogURL(*s)
	}
	return tic
}

// SetResourcePoolID sets the "resourcePoolID" field.
func (tic *TestbedInfoCreate) SetResourcePoolID(m model.ID) *TestbedInfoCreate {
	tic.mutation.SetResourcePoolID(m)
	return tic
}

// SetID sets the "id" field.
func (tic *TestbedInfoCreate) SetID(m model.ID) *TestbedInfoCreate {
	tic.mutation.SetID(m)
	return tic
}

// Mutation returns the TestbedInfoMutation object of the builder.
func (tic *TestbedInfoCreate) Mutation() *TestbedInfoMutation {
	return tic.mutation
}

// Save creates the TestbedInfo in the database.
func (tic *TestbedInfoCreate) Save(ctx context.Context) (*TestbedInfo, error) {
	var (
		err  error
		node *TestbedInfo
	)
	tic.defaults()
	if len(tic.hooks) == 0 {
		if err = tic.check(); err != nil {
			return nil, err
		}
		node, err = tic.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*TestbedInfoMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			if err = tic.check(); err != nil {
				return nil, err
			}
			tic.mutation = mutation
			if node, err = tic.sqlSave(ctx); err != nil {
				return nil, err
			}
			mutation.id = &node.ID
			mutation.done = true
			return node, err
		})
		for i := len(tic.hooks) - 1; i >= 0; i-- {
			if tic.hooks[i] == nil {
				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = tic.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, tic.mutation); err != nil {
			return nil, err
		}
	}
	return node, err
}

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

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

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

// defaults sets the default values of the builder before save.
func (tic *TestbedInfoCreate) defaults() {
	if _, ok := tic.mutation.CreatedAt(); !ok {
		v := testbedinfo.DefaultCreatedAt()
		tic.mutation.SetCreatedAt(v)
	}
	if _, ok := tic.mutation.UpdatedAt(); !ok {
		v := testbedinfo.DefaultUpdatedAt()
		tic.mutation.SetUpdatedAt(v)
	}
	if _, ok := tic.mutation.Status(); !ok {
		v := testbedinfo.DefaultStatus
		tic.mutation.SetStatus(v)
	}
	if _, ok := tic.mutation.URL(); !ok {
		v := testbedinfo.DefaultURL
		tic.mutation.SetURL(v)
	}
	if _, ok := tic.mutation.GetType(); !ok {
		v := testbedinfo.DefaultType
		tic.mutation.SetType(v)
	}
	if _, ok := tic.mutation.SetUpLogURL(); !ok {
		v := testbedinfo.DefaultSetUpLogURL
		tic.mutation.SetSetUpLogURL(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (tic *TestbedInfoCreate) check() error {
	if _, ok := tic.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "TestbedInfo.createdAt"`)}
	}
	if _, ok := tic.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updatedAt", err: errors.New(`ent: missing required field "TestbedInfo.updatedAt"`)}
	}
	if _, ok := tic.mutation.Name(); !ok {
		return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "TestbedInfo.name"`)}
	}
	if v, ok := tic.mutation.Name(); ok {
		if err := testbedinfo.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TestbedInfo.name": %w`, err)}
		}
	}
	if _, ok := tic.mutation.Status(); !ok {
		return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "TestbedInfo.status"`)}
	}
	if v, ok := tic.mutation.Status(); ok {
		if err := testbedinfo.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "TestbedInfo.status": %w`, err)}
		}
	}
	if _, ok := tic.mutation.PlanExecutionID(); !ok {
		return &ValidationError{Name: "planExecutionID", err: errors.New(`ent: missing required field "TestbedInfo.planExecutionID"`)}
	}
	if v, ok := tic.mutation.PlanExecutionID(); ok {
		if err := testbedinfo.PlanExecutionIDValidator(uint64(v)); err != nil {
			return &ValidationError{Name: "planExecutionID", err: fmt.Errorf(`ent: validator failed for field "TestbedInfo.planExecutionID": %w`, err)}
		}
	}
	if _, ok := tic.mutation.URL(); !ok {
		return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "TestbedInfo.url"`)}
	}
	if _, ok := tic.mutation.GetType(); !ok {
		return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "TestbedInfo.type"`)}
	}
	if v, ok := tic.mutation.GetType(); ok {
		if err := testbedinfo.TypeValidator(v); err != nil {
			return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "TestbedInfo.type": %w`, err)}
		}
	}
	if _, ok := tic.mutation.SetUpLogURL(); !ok {
		return &ValidationError{Name: "setUpLogURL", err: errors.New(`ent: missing required field "TestbedInfo.setUpLogURL"`)}
	}
	if _, ok := tic.mutation.ResourcePoolID(); !ok {
		return &ValidationError{Name: "resourcePoolID", err: errors.New(`ent: missing required field "TestbedInfo.resourcePoolID"`)}
	}
	if v, ok := tic.mutation.ResourcePoolID(); ok {
		if err := testbedinfo.ResourcePoolIDValidator(uint64(v)); err != nil {
			return &ValidationError{Name: "resourcePoolID", err: fmt.Errorf(`ent: validator failed for field "TestbedInfo.resourcePoolID": %w`, err)}
		}
	}
	return nil
}

func (tic *TestbedInfoCreate) sqlSave(ctx context.Context) (*TestbedInfo, error) {
	_node, _spec := tic.createSpec()
	if err := sqlgraph.CreateNode(ctx, tic.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{err.Error(), err}
		}
		return nil, err
	}
	if _spec.ID.Value != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = model.ID(id)
	}
	return _node, nil
}

func (tic *TestbedInfoCreate) createSpec() (*TestbedInfo, *sqlgraph.CreateSpec) {
	var (
		_node = &TestbedInfo{config: tic.config}
		_spec = &sqlgraph.CreateSpec{
			Table: testbedinfo.Table,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeUint64,
				Column: testbedinfo.FieldID,
			},
		}
	)
	_spec.Schema = tic.schemaConfig.TestbedInfo
	_spec.OnConflict = tic.conflict
	if id, ok := tic.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := tic.mutation.CreatedAt(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: testbedinfo.FieldCreatedAt,
		})
		_node.CreatedAt = value
	}
	if value, ok := tic.mutation.UpdatedAt(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: testbedinfo.FieldUpdatedAt,
		})
		_node.UpdatedAt = value
	}
	if value, ok := tic.mutation.Name(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: testbedinfo.FieldName,
		})
		_node.Name = value
	}
	if value, ok := tic.mutation.Status(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeEnum,
			Value:  value,
			Column: testbedinfo.FieldStatus,
		})
		_node.Status = value
	}
	if value, ok := tic.mutation.PlanExecutionID(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeUint64,
			Value:  value,
			Column: testbedinfo.FieldPlanExecutionID,
		})
		_node.PlanExecutionID = value
	}
	if value, ok := tic.mutation.URL(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: testbedinfo.FieldURL,
		})
		_node.URL = value
	}
	if value, ok := tic.mutation.LeaseDDL(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: testbedinfo.FieldLeaseDDL,
		})
		_node.LeaseDDL = &value
	}
	if value, ok := tic.mutation.InitiatedAt(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: testbedinfo.FieldInitiatedAt,
		})
		_node.InitiatedAt = &value
	}
	if value, ok := tic.mutation.ReleasedAt(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: testbedinfo.FieldReleasedAt,
		})
		_node.ReleasedAt = &value
	}
	if value, ok := tic.mutation.ReleasedBy(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeUint64,
			Value:  value,
			Column: testbedinfo.FieldReleasedBy,
		})
		_node.ReleasedBy = &value
	}
	if value, ok := tic.mutation.PhysicalResourceRequest(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeJSON,
			Value:  value,
			Column: testbedinfo.FieldPhysicalResourceRequest,
		})
		_node.PhysicalResourceRequest = value
	}
	if value, ok := tic.mutation.ResourceItems(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeJSON,
			Value:  value,
			Column: testbedinfo.FieldResourceItems,
		})
		_node.ResourceItems = value
	}
	if value, ok := tic.mutation.GetType(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeEnum,
			Value:  value,
			Column: testbedinfo.FieldType,
		})
		_node.Type = value
	}
	if value, ok := tic.mutation.SetUpLogURL(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: testbedinfo.FieldSetUpLogURL,
		})
		_node.SetUpLogURL = value
	}
	if value, ok := tic.mutation.ResourcePoolID(); ok {
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
			Type:   field.TypeUint64,
			Value:  value,
			Column: testbedinfo.FieldResourcePoolID,
		})
		_node.ResourcePoolID = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.TestbedInfo.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.TestbedInfoUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
//
func (tic *TestbedInfoCreate) OnConflict(opts ...sql.ConflictOption) *TestbedInfoUpsertOne {
	tic.conflict = opts
	return &TestbedInfoUpsertOne{
		create: tic,
	}
}

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

type (
	// TestbedInfoUpsertOne is the builder for "upsert"-ing
	//  one TestbedInfo node.
	TestbedInfoUpsertOne struct {
		create *TestbedInfoCreate
	}

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

// SetCreatedAt sets the "createdAt" field.
func (u *TestbedInfoUpsert) SetCreatedAt(v time.Time) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldCreatedAt, v)
	return u
}

// UpdateCreatedAt sets the "createdAt" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateCreatedAt() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldCreatedAt)
	return u
}

// SetUpdatedAt sets the "updatedAt" field.
func (u *TestbedInfoUpsert) SetUpdatedAt(v time.Time) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldUpdatedAt, v)
	return u
}

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

// SetName sets the "name" field.
func (u *TestbedInfoUpsert) SetName(v string) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldName, v)
	return u
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateName() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldName)
	return u
}

// SetStatus sets the "status" field.
func (u *TestbedInfoUpsert) SetStatus(v model.TestBedInfoStatus) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldStatus, v)
	return u
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateStatus() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldStatus)
	return u
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (u *TestbedInfoUpsert) SetPlanExecutionID(v model.ID) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldPlanExecutionID, v)
	return u
}

// UpdatePlanExecutionID sets the "planExecutionID" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdatePlanExecutionID() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldPlanExecutionID)
	return u
}

// AddPlanExecutionID adds v to the "planExecutionID" field.
func (u *TestbedInfoUpsert) AddPlanExecutionID(v model.ID) *TestbedInfoUpsert {
	u.Add(testbedinfo.FieldPlanExecutionID, v)
	return u
}

// SetURL sets the "url" field.
func (u *TestbedInfoUpsert) SetURL(v string) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldURL, v)
	return u
}

// UpdateURL sets the "url" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateURL() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldURL)
	return u
}

// SetLeaseDDL sets the "leaseDDL" field.
func (u *TestbedInfoUpsert) SetLeaseDDL(v time.Time) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldLeaseDDL, v)
	return u
}

// UpdateLeaseDDL sets the "leaseDDL" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateLeaseDDL() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldLeaseDDL)
	return u
}

// ClearLeaseDDL clears the value of the "leaseDDL" field.
func (u *TestbedInfoUpsert) ClearLeaseDDL() *TestbedInfoUpsert {
	u.SetNull(testbedinfo.FieldLeaseDDL)
	return u
}

// SetInitiatedAt sets the "initiatedAt" field.
func (u *TestbedInfoUpsert) SetInitiatedAt(v time.Time) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldInitiatedAt, v)
	return u
}

// UpdateInitiatedAt sets the "initiatedAt" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateInitiatedAt() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldInitiatedAt)
	return u
}

// ClearInitiatedAt clears the value of the "initiatedAt" field.
func (u *TestbedInfoUpsert) ClearInitiatedAt() *TestbedInfoUpsert {
	u.SetNull(testbedinfo.FieldInitiatedAt)
	return u
}

// SetReleasedAt sets the "releasedAt" field.
func (u *TestbedInfoUpsert) SetReleasedAt(v time.Time) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldReleasedAt, v)
	return u
}

// UpdateReleasedAt sets the "releasedAt" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateReleasedAt() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldReleasedAt)
	return u
}

// ClearReleasedAt clears the value of the "releasedAt" field.
func (u *TestbedInfoUpsert) ClearReleasedAt() *TestbedInfoUpsert {
	u.SetNull(testbedinfo.FieldReleasedAt)
	return u
}

// SetReleasedBy sets the "releasedBy" field.
func (u *TestbedInfoUpsert) SetReleasedBy(v model.ID) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldReleasedBy, v)
	return u
}

// UpdateReleasedBy sets the "releasedBy" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateReleasedBy() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldReleasedBy)
	return u
}

// AddReleasedBy adds v to the "releasedBy" field.
func (u *TestbedInfoUpsert) AddReleasedBy(v model.ID) *TestbedInfoUpsert {
	u.Add(testbedinfo.FieldReleasedBy, v)
	return u
}

// ClearReleasedBy clears the value of the "releasedBy" field.
func (u *TestbedInfoUpsert) ClearReleasedBy() *TestbedInfoUpsert {
	u.SetNull(testbedinfo.FieldReleasedBy)
	return u
}

// SetPhysicalResourceRequest sets the "physicalResourceRequest" field.
func (u *TestbedInfoUpsert) SetPhysicalResourceRequest(v model.PhysicalResource) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldPhysicalResourceRequest, v)
	return u
}

// UpdatePhysicalResourceRequest sets the "physicalResourceRequest" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdatePhysicalResourceRequest() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldPhysicalResourceRequest)
	return u
}

// ClearPhysicalResourceRequest clears the value of the "physicalResourceRequest" field.
func (u *TestbedInfoUpsert) ClearPhysicalResourceRequest() *TestbedInfoUpsert {
	u.SetNull(testbedinfo.FieldPhysicalResourceRequest)
	return u
}

// SetResourceItems sets the "resourceItems" field.
func (u *TestbedInfoUpsert) SetResourceItems(v []model.TestBedInfoResourceItem) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldResourceItems, v)
	return u
}

// UpdateResourceItems sets the "resourceItems" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateResourceItems() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldResourceItems)
	return u
}

// ClearResourceItems clears the value of the "resourceItems" field.
func (u *TestbedInfoUpsert) ClearResourceItems() *TestbedInfoUpsert {
	u.SetNull(testbedinfo.FieldResourceItems)
	return u
}

// SetType sets the "type" field.
func (u *TestbedInfoUpsert) SetType(v model.TestBedInfoType) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldType, v)
	return u
}

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

// SetSetUpLogURL sets the "setUpLogURL" field.
func (u *TestbedInfoUpsert) SetSetUpLogURL(v string) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldSetUpLogURL, v)
	return u
}

// UpdateSetUpLogURL sets the "setUpLogURL" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateSetUpLogURL() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldSetUpLogURL)
	return u
}

// SetResourcePoolID sets the "resourcePoolID" field.
func (u *TestbedInfoUpsert) SetResourcePoolID(v model.ID) *TestbedInfoUpsert {
	u.Set(testbedinfo.FieldResourcePoolID, v)
	return u
}

// UpdateResourcePoolID sets the "resourcePoolID" field to the value that was provided on create.
func (u *TestbedInfoUpsert) UpdateResourcePoolID() *TestbedInfoUpsert {
	u.SetExcluded(testbedinfo.FieldResourcePoolID)
	return u
}

// AddResourcePoolID adds v to the "resourcePoolID" field.
func (u *TestbedInfoUpsert) AddResourcePoolID(v model.ID) *TestbedInfoUpsert {
	u.Add(testbedinfo.FieldResourcePoolID, v)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.TestbedInfo.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(testbedinfo.FieldID)
//			}),
//		).
//		Exec(ctx)
//
func (u *TestbedInfoUpsertOne) UpdateNewValues() *TestbedInfoUpsertOne {
	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.ID(); exists {
			s.SetIgnore(testbedinfo.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(testbedinfo.FieldCreatedAt)
		}
		if _, exists := u.create.mutation.UpdatedAt(); exists {
			s.SetIgnore(testbedinfo.FieldUpdatedAt)
		}
		if _, exists := u.create.mutation.Name(); exists {
			s.SetIgnore(testbedinfo.FieldName)
		}
		if _, exists := u.create.mutation.PlanExecutionID(); exists {
			s.SetIgnore(testbedinfo.FieldPlanExecutionID)
		}
		if _, exists := u.create.mutation.ResourcePoolID(); exists {
			s.SetIgnore(testbedinfo.FieldResourcePoolID)
		}
	}))
	return u
}

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

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

// SetCreatedAt sets the "createdAt" field.
func (u *TestbedInfoUpsertOne) SetCreatedAt(v time.Time) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetCreatedAt(v)
	})
}

// UpdateCreatedAt sets the "createdAt" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateCreatedAt() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateCreatedAt()
	})
}

// SetUpdatedAt sets the "updatedAt" field.
func (u *TestbedInfoUpsertOne) SetUpdatedAt(v time.Time) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetUpdatedAt(v)
	})
}

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

// SetName sets the "name" field.
func (u *TestbedInfoUpsertOne) SetName(v string) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateName() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateName()
	})
}

// SetStatus sets the "status" field.
func (u *TestbedInfoUpsertOne) SetStatus(v model.TestBedInfoStatus) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateStatus() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateStatus()
	})
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (u *TestbedInfoUpsertOne) SetPlanExecutionID(v model.ID) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetPlanExecutionID(v)
	})
}

// AddPlanExecutionID adds v to the "planExecutionID" field.
func (u *TestbedInfoUpsertOne) AddPlanExecutionID(v model.ID) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.AddPlanExecutionID(v)
	})
}

// UpdatePlanExecutionID sets the "planExecutionID" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdatePlanExecutionID() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdatePlanExecutionID()
	})
}

// SetURL sets the "url" field.
func (u *TestbedInfoUpsertOne) SetURL(v string) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetURL(v)
	})
}

// UpdateURL sets the "url" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateURL() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateURL()
	})
}

// SetLeaseDDL sets the "leaseDDL" field.
func (u *TestbedInfoUpsertOne) SetLeaseDDL(v time.Time) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetLeaseDDL(v)
	})
}

// UpdateLeaseDDL sets the "leaseDDL" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateLeaseDDL() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateLeaseDDL()
	})
}

// ClearLeaseDDL clears the value of the "leaseDDL" field.
func (u *TestbedInfoUpsertOne) ClearLeaseDDL() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearLeaseDDL()
	})
}

// SetInitiatedAt sets the "initiatedAt" field.
func (u *TestbedInfoUpsertOne) SetInitiatedAt(v time.Time) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetInitiatedAt(v)
	})
}

// UpdateInitiatedAt sets the "initiatedAt" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateInitiatedAt() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateInitiatedAt()
	})
}

// ClearInitiatedAt clears the value of the "initiatedAt" field.
func (u *TestbedInfoUpsertOne) ClearInitiatedAt() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearInitiatedAt()
	})
}

// SetReleasedAt sets the "releasedAt" field.
func (u *TestbedInfoUpsertOne) SetReleasedAt(v time.Time) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetReleasedAt(v)
	})
}

// UpdateReleasedAt sets the "releasedAt" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateReleasedAt() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateReleasedAt()
	})
}

// ClearReleasedAt clears the value of the "releasedAt" field.
func (u *TestbedInfoUpsertOne) ClearReleasedAt() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearReleasedAt()
	})
}

// SetReleasedBy sets the "releasedBy" field.
func (u *TestbedInfoUpsertOne) SetReleasedBy(v model.ID) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetReleasedBy(v)
	})
}

// AddReleasedBy adds v to the "releasedBy" field.
func (u *TestbedInfoUpsertOne) AddReleasedBy(v model.ID) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.AddReleasedBy(v)
	})
}

// UpdateReleasedBy sets the "releasedBy" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateReleasedBy() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateReleasedBy()
	})
}

// ClearReleasedBy clears the value of the "releasedBy" field.
func (u *TestbedInfoUpsertOne) ClearReleasedBy() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearReleasedBy()
	})
}

// SetPhysicalResourceRequest sets the "physicalResourceRequest" field.
func (u *TestbedInfoUpsertOne) SetPhysicalResourceRequest(v model.PhysicalResource) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetPhysicalResourceRequest(v)
	})
}

// UpdatePhysicalResourceRequest sets the "physicalResourceRequest" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdatePhysicalResourceRequest() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdatePhysicalResourceRequest()
	})
}

// ClearPhysicalResourceRequest clears the value of the "physicalResourceRequest" field.
func (u *TestbedInfoUpsertOne) ClearPhysicalResourceRequest() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearPhysicalResourceRequest()
	})
}

// SetResourceItems sets the "resourceItems" field.
func (u *TestbedInfoUpsertOne) SetResourceItems(v []model.TestBedInfoResourceItem) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetResourceItems(v)
	})
}

// UpdateResourceItems sets the "resourceItems" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateResourceItems() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateResourceItems()
	})
}

// ClearResourceItems clears the value of the "resourceItems" field.
func (u *TestbedInfoUpsertOne) ClearResourceItems() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearResourceItems()
	})
}

// SetType sets the "type" field.
func (u *TestbedInfoUpsertOne) SetType(v model.TestBedInfoType) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetType(v)
	})
}

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

// SetSetUpLogURL sets the "setUpLogURL" field.
func (u *TestbedInfoUpsertOne) SetSetUpLogURL(v string) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetSetUpLogURL(v)
	})
}

// UpdateSetUpLogURL sets the "setUpLogURL" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateSetUpLogURL() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateSetUpLogURL()
	})
}

// SetResourcePoolID sets the "resourcePoolID" field.
func (u *TestbedInfoUpsertOne) SetResourcePoolID(v model.ID) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetResourcePoolID(v)
	})
}

// AddResourcePoolID adds v to the "resourcePoolID" field.
func (u *TestbedInfoUpsertOne) AddResourcePoolID(v model.ID) *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.AddResourcePoolID(v)
	})
}

// UpdateResourcePoolID sets the "resourcePoolID" field to the value that was provided on create.
func (u *TestbedInfoUpsertOne) UpdateResourcePoolID() *TestbedInfoUpsertOne {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateResourcePoolID()
	})
}

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

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

// TestbedInfoCreateBulk is the builder for creating many TestbedInfo entities in bulk.
type TestbedInfoCreateBulk struct {
	config
	builders []*TestbedInfoCreate
	conflict []sql.ConflictOption
}

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.TestbedInfo.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.TestbedInfoUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
//
func (ticb *TestbedInfoCreateBulk) OnConflict(opts ...sql.ConflictOption) *TestbedInfoUpsertBulk {
	ticb.conflict = opts
	return &TestbedInfoUpsertBulk{
		create: ticb,
	}
}

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

// TestbedInfoUpsertBulk is the builder for "upsert"-ing
// a bulk of TestbedInfo nodes.
type TestbedInfoUpsertBulk struct {
	create *TestbedInfoCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.TestbedInfo.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(testbedinfo.FieldID)
//			}),
//		).
//		Exec(ctx)
//
func (u *TestbedInfoUpsertBulk) UpdateNewValues() *TestbedInfoUpsertBulk {
	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.ID(); exists {
				s.SetIgnore(testbedinfo.FieldID)
				return
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(testbedinfo.FieldCreatedAt)
			}
			if _, exists := b.mutation.UpdatedAt(); exists {
				s.SetIgnore(testbedinfo.FieldUpdatedAt)
			}
			if _, exists := b.mutation.Name(); exists {
				s.SetIgnore(testbedinfo.FieldName)
			}
			if _, exists := b.mutation.PlanExecutionID(); exists {
				s.SetIgnore(testbedinfo.FieldPlanExecutionID)
			}
			if _, exists := b.mutation.ResourcePoolID(); exists {
				s.SetIgnore(testbedinfo.FieldResourcePoolID)
			}
		}
	}))
	return u
}

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

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

// SetCreatedAt sets the "createdAt" field.
func (u *TestbedInfoUpsertBulk) SetCreatedAt(v time.Time) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetCreatedAt(v)
	})
}

// UpdateCreatedAt sets the "createdAt" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateCreatedAt() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateCreatedAt()
	})
}

// SetUpdatedAt sets the "updatedAt" field.
func (u *TestbedInfoUpsertBulk) SetUpdatedAt(v time.Time) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetUpdatedAt(v)
	})
}

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

// SetName sets the "name" field.
func (u *TestbedInfoUpsertBulk) SetName(v string) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateName() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateName()
	})
}

// SetStatus sets the "status" field.
func (u *TestbedInfoUpsertBulk) SetStatus(v model.TestBedInfoStatus) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateStatus() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateStatus()
	})
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (u *TestbedInfoUpsertBulk) SetPlanExecutionID(v model.ID) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetPlanExecutionID(v)
	})
}

// AddPlanExecutionID adds v to the "planExecutionID" field.
func (u *TestbedInfoUpsertBulk) AddPlanExecutionID(v model.ID) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.AddPlanExecutionID(v)
	})
}

// UpdatePlanExecutionID sets the "planExecutionID" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdatePlanExecutionID() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdatePlanExecutionID()
	})
}

// SetURL sets the "url" field.
func (u *TestbedInfoUpsertBulk) SetURL(v string) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetURL(v)
	})
}

// UpdateURL sets the "url" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateURL() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateURL()
	})
}

// SetLeaseDDL sets the "leaseDDL" field.
func (u *TestbedInfoUpsertBulk) SetLeaseDDL(v time.Time) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetLeaseDDL(v)
	})
}

// UpdateLeaseDDL sets the "leaseDDL" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateLeaseDDL() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateLeaseDDL()
	})
}

// ClearLeaseDDL clears the value of the "leaseDDL" field.
func (u *TestbedInfoUpsertBulk) ClearLeaseDDL() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearLeaseDDL()
	})
}

// SetInitiatedAt sets the "initiatedAt" field.
func (u *TestbedInfoUpsertBulk) SetInitiatedAt(v time.Time) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetInitiatedAt(v)
	})
}

// UpdateInitiatedAt sets the "initiatedAt" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateInitiatedAt() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateInitiatedAt()
	})
}

// ClearInitiatedAt clears the value of the "initiatedAt" field.
func (u *TestbedInfoUpsertBulk) ClearInitiatedAt() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearInitiatedAt()
	})
}

// SetReleasedAt sets the "releasedAt" field.
func (u *TestbedInfoUpsertBulk) SetReleasedAt(v time.Time) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetReleasedAt(v)
	})
}

// UpdateReleasedAt sets the "releasedAt" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateReleasedAt() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateReleasedAt()
	})
}

// ClearReleasedAt clears the value of the "releasedAt" field.
func (u *TestbedInfoUpsertBulk) ClearReleasedAt() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearReleasedAt()
	})
}

// SetReleasedBy sets the "releasedBy" field.
func (u *TestbedInfoUpsertBulk) SetReleasedBy(v model.ID) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetReleasedBy(v)
	})
}

// AddReleasedBy adds v to the "releasedBy" field.
func (u *TestbedInfoUpsertBulk) AddReleasedBy(v model.ID) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.AddReleasedBy(v)
	})
}

// UpdateReleasedBy sets the "releasedBy" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateReleasedBy() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateReleasedBy()
	})
}

// ClearReleasedBy clears the value of the "releasedBy" field.
func (u *TestbedInfoUpsertBulk) ClearReleasedBy() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearReleasedBy()
	})
}

// SetPhysicalResourceRequest sets the "physicalResourceRequest" field.
func (u *TestbedInfoUpsertBulk) SetPhysicalResourceRequest(v model.PhysicalResource) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetPhysicalResourceRequest(v)
	})
}

// UpdatePhysicalResourceRequest sets the "physicalResourceRequest" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdatePhysicalResourceRequest() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdatePhysicalResourceRequest()
	})
}

// ClearPhysicalResourceRequest clears the value of the "physicalResourceRequest" field.
func (u *TestbedInfoUpsertBulk) ClearPhysicalResourceRequest() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearPhysicalResourceRequest()
	})
}

// SetResourceItems sets the "resourceItems" field.
func (u *TestbedInfoUpsertBulk) SetResourceItems(v []model.TestBedInfoResourceItem) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetResourceItems(v)
	})
}

// UpdateResourceItems sets the "resourceItems" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateResourceItems() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateResourceItems()
	})
}

// ClearResourceItems clears the value of the "resourceItems" field.
func (u *TestbedInfoUpsertBulk) ClearResourceItems() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.ClearResourceItems()
	})
}

// SetType sets the "type" field.
func (u *TestbedInfoUpsertBulk) SetType(v model.TestBedInfoType) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetType(v)
	})
}

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

// SetSetUpLogURL sets the "setUpLogURL" field.
func (u *TestbedInfoUpsertBulk) SetSetUpLogURL(v string) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetSetUpLogURL(v)
	})
}

// UpdateSetUpLogURL sets the "setUpLogURL" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateSetUpLogURL() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateSetUpLogURL()
	})
}

// SetResourcePoolID sets the "resourcePoolID" field.
func (u *TestbedInfoUpsertBulk) SetResourcePoolID(v model.ID) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.SetResourcePoolID(v)
	})
}

// AddResourcePoolID adds v to the "resourcePoolID" field.
func (u *TestbedInfoUpsertBulk) AddResourcePoolID(v model.ID) *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.AddResourcePoolID(v)
	})
}

// UpdateResourcePoolID sets the "resourcePoolID" field to the value that was provided on create.
func (u *TestbedInfoUpsertBulk) UpdateResourcePoolID() *TestbedInfoUpsertBulk {
	return u.Update(func(s *TestbedInfoUpsert) {
		s.UpdateResourcePoolID()
	})
}

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

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