// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontract"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontractversion"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/unmarshal"
	"github.com/google/uuid"
)

// WorkflowContractVersionCreate is the builder for creating a WorkflowContractVersion entity.
type WorkflowContractVersionCreate struct {
	config
	mutation *WorkflowContractVersionMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetBody sets the "body" field.
func (wcvc *WorkflowContractVersionCreate) SetBody(b []byte) *WorkflowContractVersionCreate {
	wcvc.mutation.SetBody(b)
	return wcvc
}

// SetRawBody sets the "raw_body" field.
func (wcvc *WorkflowContractVersionCreate) SetRawBody(b []byte) *WorkflowContractVersionCreate {
	wcvc.mutation.SetRawBody(b)
	return wcvc
}

// SetRawBodyFormat sets the "raw_body_format" field.
func (wcvc *WorkflowContractVersionCreate) SetRawBodyFormat(uf unmarshal.RawFormat) *WorkflowContractVersionCreate {
	wcvc.mutation.SetRawBodyFormat(uf)
	return wcvc
}

// SetRevision sets the "revision" field.
func (wcvc *WorkflowContractVersionCreate) SetRevision(i int) *WorkflowContractVersionCreate {
	wcvc.mutation.SetRevision(i)
	return wcvc
}

// SetNillableRevision sets the "revision" field if the given value is not nil.
func (wcvc *WorkflowContractVersionCreate) SetNillableRevision(i *int) *WorkflowContractVersionCreate {
	if i != nil {
		wcvc.SetRevision(*i)
	}
	return wcvc
}

// SetCreatedAt sets the "created_at" field.
func (wcvc *WorkflowContractVersionCreate) SetCreatedAt(t time.Time) *WorkflowContractVersionCreate {
	wcvc.mutation.SetCreatedAt(t)
	return wcvc
}

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

// SetID sets the "id" field.
func (wcvc *WorkflowContractVersionCreate) SetID(u uuid.UUID) *WorkflowContractVersionCreate {
	wcvc.mutation.SetID(u)
	return wcvc
}

// SetNillableID sets the "id" field if the given value is not nil.
func (wcvc *WorkflowContractVersionCreate) SetNillableID(u *uuid.UUID) *WorkflowContractVersionCreate {
	if u != nil {
		wcvc.SetID(*u)
	}
	return wcvc
}

// SetContractID sets the "contract" edge to the WorkflowContract entity by ID.
func (wcvc *WorkflowContractVersionCreate) SetContractID(id uuid.UUID) *WorkflowContractVersionCreate {
	wcvc.mutation.SetContractID(id)
	return wcvc
}

// SetNillableContractID sets the "contract" edge to the WorkflowContract entity by ID if the given value is not nil.
func (wcvc *WorkflowContractVersionCreate) SetNillableContractID(id *uuid.UUID) *WorkflowContractVersionCreate {
	if id != nil {
		wcvc = wcvc.SetContractID(*id)
	}
	return wcvc
}

// SetContract sets the "contract" edge to the WorkflowContract entity.
func (wcvc *WorkflowContractVersionCreate) SetContract(w *WorkflowContract) *WorkflowContractVersionCreate {
	return wcvc.SetContractID(w.ID)
}

// Mutation returns the WorkflowContractVersionMutation object of the builder.
func (wcvc *WorkflowContractVersionCreate) Mutation() *WorkflowContractVersionMutation {
	return wcvc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (wcvc *WorkflowContractVersionCreate) defaults() {
	if _, ok := wcvc.mutation.Revision(); !ok {
		v := workflowcontractversion.DefaultRevision
		wcvc.mutation.SetRevision(v)
	}
	if _, ok := wcvc.mutation.CreatedAt(); !ok {
		v := workflowcontractversion.DefaultCreatedAt()
		wcvc.mutation.SetCreatedAt(v)
	}
	if _, ok := wcvc.mutation.ID(); !ok {
		v := workflowcontractversion.DefaultID()
		wcvc.mutation.SetID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (wcvc *WorkflowContractVersionCreate) check() error {
	if _, ok := wcvc.mutation.RawBody(); !ok {
		return &ValidationError{Name: "raw_body", err: errors.New(`ent: missing required field "WorkflowContractVersion.raw_body"`)}
	}
	if v, ok := wcvc.mutation.RawBody(); ok {
		if err := workflowcontractversion.RawBodyValidator(v); err != nil {
			return &ValidationError{Name: "raw_body", err: fmt.Errorf(`ent: validator failed for field "WorkflowContractVersion.raw_body": %w`, err)}
		}
	}
	if _, ok := wcvc.mutation.RawBodyFormat(); !ok {
		return &ValidationError{Name: "raw_body_format", err: errors.New(`ent: missing required field "WorkflowContractVersion.raw_body_format"`)}
	}
	if v, ok := wcvc.mutation.RawBodyFormat(); ok {
		if err := workflowcontractversion.RawBodyFormatValidator(v); err != nil {
			return &ValidationError{Name: "raw_body_format", err: fmt.Errorf(`ent: validator failed for field "WorkflowContractVersion.raw_body_format": %w`, err)}
		}
	}
	if _, ok := wcvc.mutation.Revision(); !ok {
		return &ValidationError{Name: "revision", err: errors.New(`ent: missing required field "WorkflowContractVersion.revision"`)}
	}
	if _, ok := wcvc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WorkflowContractVersion.created_at"`)}
	}
	return nil
}

func (wcvc *WorkflowContractVersionCreate) sqlSave(ctx context.Context) (*WorkflowContractVersion, error) {
	if err := wcvc.check(); err != nil {
		return nil, err
	}
	_node, _spec := wcvc.createSpec()
	if err := sqlgraph.CreateNode(ctx, wcvc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != nil {
		if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
			_node.ID = *id
		} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
			return nil, err
		}
	}
	wcvc.mutation.id = &_node.ID
	wcvc.mutation.done = true
	return _node, nil
}

func (wcvc *WorkflowContractVersionCreate) createSpec() (*WorkflowContractVersion, *sqlgraph.CreateSpec) {
	var (
		_node = &WorkflowContractVersion{config: wcvc.config}
		_spec = sqlgraph.NewCreateSpec(workflowcontractversion.Table, sqlgraph.NewFieldSpec(workflowcontractversion.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = wcvc.conflict
	if id, ok := wcvc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := wcvc.mutation.Body(); ok {
		_spec.SetField(workflowcontractversion.FieldBody, field.TypeBytes, value)
		_node.Body = value
	}
	if value, ok := wcvc.mutation.RawBody(); ok {
		_spec.SetField(workflowcontractversion.FieldRawBody, field.TypeBytes, value)
		_node.RawBody = value
	}
	if value, ok := wcvc.mutation.RawBodyFormat(); ok {
		_spec.SetField(workflowcontractversion.FieldRawBodyFormat, field.TypeEnum, value)
		_node.RawBodyFormat = value
	}
	if value, ok := wcvc.mutation.Revision(); ok {
		_spec.SetField(workflowcontractversion.FieldRevision, field.TypeInt, value)
		_node.Revision = value
	}
	if value, ok := wcvc.mutation.CreatedAt(); ok {
		_spec.SetField(workflowcontractversion.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if nodes := wcvc.mutation.ContractIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflowcontractversion.ContractTable,
			Columns: []string{workflowcontractversion.ContractColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.workflow_contract_versions = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WorkflowContractVersion.Create().
//		SetBody(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.WorkflowContractVersionUpsert) {
//			SetBody(v+v).
//		}).
//		Exec(ctx)
func (wcvc *WorkflowContractVersionCreate) OnConflict(opts ...sql.ConflictOption) *WorkflowContractVersionUpsertOne {
	wcvc.conflict = opts
	return &WorkflowContractVersionUpsertOne{
		create: wcvc,
	}
}

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

type (
	// WorkflowContractVersionUpsertOne is the builder for "upsert"-ing
	//  one WorkflowContractVersion node.
	WorkflowContractVersionUpsertOne struct {
		create *WorkflowContractVersionCreate
	}

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

// SetRawBodyFormat sets the "raw_body_format" field.
func (u *WorkflowContractVersionUpsert) SetRawBodyFormat(v unmarshal.RawFormat) *WorkflowContractVersionUpsert {
	u.Set(workflowcontractversion.FieldRawBodyFormat, v)
	return u
}

// UpdateRawBodyFormat sets the "raw_body_format" field to the value that was provided on create.
func (u *WorkflowContractVersionUpsert) UpdateRawBodyFormat() *WorkflowContractVersionUpsert {
	u.SetExcluded(workflowcontractversion.FieldRawBodyFormat)
	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.WorkflowContractVersion.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(workflowcontractversion.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WorkflowContractVersionUpsertOne) UpdateNewValues() *WorkflowContractVersionUpsertOne {
	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(workflowcontractversion.FieldID)
		}
		if _, exists := u.create.mutation.Body(); exists {
			s.SetIgnore(workflowcontractversion.FieldBody)
		}
		if _, exists := u.create.mutation.RawBody(); exists {
			s.SetIgnore(workflowcontractversion.FieldRawBody)
		}
		if _, exists := u.create.mutation.Revision(); exists {
			s.SetIgnore(workflowcontractversion.FieldRevision)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(workflowcontractversion.FieldCreatedAt)
		}
	}))
	return u
}

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

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

// SetRawBodyFormat sets the "raw_body_format" field.
func (u *WorkflowContractVersionUpsertOne) SetRawBodyFormat(v unmarshal.RawFormat) *WorkflowContractVersionUpsertOne {
	return u.Update(func(s *WorkflowContractVersionUpsert) {
		s.SetRawBodyFormat(v)
	})
}

// UpdateRawBodyFormat sets the "raw_body_format" field to the value that was provided on create.
func (u *WorkflowContractVersionUpsertOne) UpdateRawBodyFormat() *WorkflowContractVersionUpsertOne {
	return u.Update(func(s *WorkflowContractVersionUpsert) {
		s.UpdateRawBodyFormat()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *WorkflowContractVersionUpsertOne) 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 *WorkflowContractVersionUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
	if u.create.driver.Dialect() == dialect.MySQL {
		// In case of "ON CONFLICT", there is no way to get back non-numeric ID
		// fields from the database since MySQL does not support the RETURNING clause.
		return id, errors.New("ent: WorkflowContractVersionUpsertOne.ID is not supported by MySQL driver. Use WorkflowContractVersionUpsertOne.Exec instead")
	}
	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 *WorkflowContractVersionUpsertOne) IDX(ctx context.Context) uuid.UUID {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

// Save creates the WorkflowContractVersion entities in the database.
func (wcvcb *WorkflowContractVersionCreateBulk) Save(ctx context.Context) ([]*WorkflowContractVersion, error) {
	if wcvcb.err != nil {
		return nil, wcvcb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(wcvcb.builders))
	nodes := make([]*WorkflowContractVersion, len(wcvcb.builders))
	mutators := make([]Mutator, len(wcvcb.builders))
	for i := range wcvcb.builders {
		func(i int, root context.Context) {
			builder := wcvcb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*WorkflowContractVersionMutation)
				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, wcvcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = wcvcb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, wcvcb.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
				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, wcvcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WorkflowContractVersion.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.WorkflowContractVersionUpsert) {
//			SetBody(v+v).
//		}).
//		Exec(ctx)
func (wcvcb *WorkflowContractVersionCreateBulk) OnConflict(opts ...sql.ConflictOption) *WorkflowContractVersionUpsertBulk {
	wcvcb.conflict = opts
	return &WorkflowContractVersionUpsertBulk{
		create: wcvcb,
	}
}

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

// WorkflowContractVersionUpsertBulk is the builder for "upsert"-ing
// a bulk of WorkflowContractVersion nodes.
type WorkflowContractVersionUpsertBulk struct {
	create *WorkflowContractVersionCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.WorkflowContractVersion.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(workflowcontractversion.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WorkflowContractVersionUpsertBulk) UpdateNewValues() *WorkflowContractVersionUpsertBulk {
	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(workflowcontractversion.FieldID)
			}
			if _, exists := b.mutation.Body(); exists {
				s.SetIgnore(workflowcontractversion.FieldBody)
			}
			if _, exists := b.mutation.RawBody(); exists {
				s.SetIgnore(workflowcontractversion.FieldRawBody)
			}
			if _, exists := b.mutation.Revision(); exists {
				s.SetIgnore(workflowcontractversion.FieldRevision)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(workflowcontractversion.FieldCreatedAt)
			}
		}
	}))
	return u
}

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

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

// SetRawBodyFormat sets the "raw_body_format" field.
func (u *WorkflowContractVersionUpsertBulk) SetRawBodyFormat(v unmarshal.RawFormat) *WorkflowContractVersionUpsertBulk {
	return u.Update(func(s *WorkflowContractVersionUpsert) {
		s.SetRawBodyFormat(v)
	})
}

// UpdateRawBodyFormat sets the "raw_body_format" field to the value that was provided on create.
func (u *WorkflowContractVersionUpsertBulk) UpdateRawBodyFormat() *WorkflowContractVersionUpsertBulk {
	return u.Update(func(s *WorkflowContractVersionUpsert) {
		s.UpdateRawBodyFormat()
	})
}

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

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