// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"registry-backend/ent/ciworkflowresult"
	"registry-backend/ent/gitcommit"
	"time"

	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
)

// GitCommitCreate is the builder for creating a GitCommit entity.
type GitCommitCreate struct {
	config
	mutation *GitCommitMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreateTime sets the "create_time" field.
func (gcc *GitCommitCreate) SetCreateTime(t time.Time) *GitCommitCreate {
	gcc.mutation.SetCreateTime(t)
	return gcc
}

// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (gcc *GitCommitCreate) SetNillableCreateTime(t *time.Time) *GitCommitCreate {
	if t != nil {
		gcc.SetCreateTime(*t)
	}
	return gcc
}

// SetUpdateTime sets the "update_time" field.
func (gcc *GitCommitCreate) SetUpdateTime(t time.Time) *GitCommitCreate {
	gcc.mutation.SetUpdateTime(t)
	return gcc
}

// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
func (gcc *GitCommitCreate) SetNillableUpdateTime(t *time.Time) *GitCommitCreate {
	if t != nil {
		gcc.SetUpdateTime(*t)
	}
	return gcc
}

// SetCommitHash sets the "commit_hash" field.
func (gcc *GitCommitCreate) SetCommitHash(s string) *GitCommitCreate {
	gcc.mutation.SetCommitHash(s)
	return gcc
}

// SetBranchName sets the "branch_name" field.
func (gcc *GitCommitCreate) SetBranchName(s string) *GitCommitCreate {
	gcc.mutation.SetBranchName(s)
	return gcc
}

// SetRepoName sets the "repo_name" field.
func (gcc *GitCommitCreate) SetRepoName(s string) *GitCommitCreate {
	gcc.mutation.SetRepoName(s)
	return gcc
}

// SetCommitMessage sets the "commit_message" field.
func (gcc *GitCommitCreate) SetCommitMessage(s string) *GitCommitCreate {
	gcc.mutation.SetCommitMessage(s)
	return gcc
}

// SetCommitTimestamp sets the "commit_timestamp" field.
func (gcc *GitCommitCreate) SetCommitTimestamp(t time.Time) *GitCommitCreate {
	gcc.mutation.SetCommitTimestamp(t)
	return gcc
}

// SetAuthor sets the "author" field.
func (gcc *GitCommitCreate) SetAuthor(s string) *GitCommitCreate {
	gcc.mutation.SetAuthor(s)
	return gcc
}

// SetNillableAuthor sets the "author" field if the given value is not nil.
func (gcc *GitCommitCreate) SetNillableAuthor(s *string) *GitCommitCreate {
	if s != nil {
		gcc.SetAuthor(*s)
	}
	return gcc
}

// SetTimestamp sets the "timestamp" field.
func (gcc *GitCommitCreate) SetTimestamp(t time.Time) *GitCommitCreate {
	gcc.mutation.SetTimestamp(t)
	return gcc
}

// SetNillableTimestamp sets the "timestamp" field if the given value is not nil.
func (gcc *GitCommitCreate) SetNillableTimestamp(t *time.Time) *GitCommitCreate {
	if t != nil {
		gcc.SetTimestamp(*t)
	}
	return gcc
}

// SetPrNumber sets the "pr_number" field.
func (gcc *GitCommitCreate) SetPrNumber(s string) *GitCommitCreate {
	gcc.mutation.SetPrNumber(s)
	return gcc
}

// SetNillablePrNumber sets the "pr_number" field if the given value is not nil.
func (gcc *GitCommitCreate) SetNillablePrNumber(s *string) *GitCommitCreate {
	if s != nil {
		gcc.SetPrNumber(*s)
	}
	return gcc
}

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

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

// AddResultIDs adds the "results" edge to the CIWorkflowResult entity by IDs.
func (gcc *GitCommitCreate) AddResultIDs(ids ...uuid.UUID) *GitCommitCreate {
	gcc.mutation.AddResultIDs(ids...)
	return gcc
}

// AddResults adds the "results" edges to the CIWorkflowResult entity.
func (gcc *GitCommitCreate) AddResults(c ...*CIWorkflowResult) *GitCommitCreate {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return gcc.AddResultIDs(ids...)
}

// Mutation returns the GitCommitMutation object of the builder.
func (gcc *GitCommitCreate) Mutation() *GitCommitMutation {
	return gcc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (gcc *GitCommitCreate) defaults() {
	if _, ok := gcc.mutation.CreateTime(); !ok {
		v := gitcommit.DefaultCreateTime()
		gcc.mutation.SetCreateTime(v)
	}
	if _, ok := gcc.mutation.UpdateTime(); !ok {
		v := gitcommit.DefaultUpdateTime()
		gcc.mutation.SetUpdateTime(v)
	}
	if _, ok := gcc.mutation.ID(); !ok {
		v := gitcommit.DefaultID()
		gcc.mutation.SetID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (gcc *GitCommitCreate) check() error {
	if _, ok := gcc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "GitCommit.create_time"`)}
	}
	if _, ok := gcc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "GitCommit.update_time"`)}
	}
	if _, ok := gcc.mutation.CommitHash(); !ok {
		return &ValidationError{Name: "commit_hash", err: errors.New(`ent: missing required field "GitCommit.commit_hash"`)}
	}
	if _, ok := gcc.mutation.BranchName(); !ok {
		return &ValidationError{Name: "branch_name", err: errors.New(`ent: missing required field "GitCommit.branch_name"`)}
	}
	if _, ok := gcc.mutation.RepoName(); !ok {
		return &ValidationError{Name: "repo_name", err: errors.New(`ent: missing required field "GitCommit.repo_name"`)}
	}
	if _, ok := gcc.mutation.CommitMessage(); !ok {
		return &ValidationError{Name: "commit_message", err: errors.New(`ent: missing required field "GitCommit.commit_message"`)}
	}
	if _, ok := gcc.mutation.CommitTimestamp(); !ok {
		return &ValidationError{Name: "commit_timestamp", err: errors.New(`ent: missing required field "GitCommit.commit_timestamp"`)}
	}
	return nil
}

func (gcc *GitCommitCreate) sqlSave(ctx context.Context) (*GitCommit, error) {
	if err := gcc.check(); err != nil {
		return nil, err
	}
	_node, _spec := gcc.createSpec()
	if err := sqlgraph.CreateNode(ctx, gcc.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
		}
	}
	gcc.mutation.id = &_node.ID
	gcc.mutation.done = true
	return _node, nil
}

func (gcc *GitCommitCreate) createSpec() (*GitCommit, *sqlgraph.CreateSpec) {
	var (
		_node = &GitCommit{config: gcc.config}
		_spec = sqlgraph.NewCreateSpec(gitcommit.Table, sqlgraph.NewFieldSpec(gitcommit.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = gcc.conflict
	if id, ok := gcc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := gcc.mutation.CreateTime(); ok {
		_spec.SetField(gitcommit.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := gcc.mutation.UpdateTime(); ok {
		_spec.SetField(gitcommit.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := gcc.mutation.CommitHash(); ok {
		_spec.SetField(gitcommit.FieldCommitHash, field.TypeString, value)
		_node.CommitHash = value
	}
	if value, ok := gcc.mutation.BranchName(); ok {
		_spec.SetField(gitcommit.FieldBranchName, field.TypeString, value)
		_node.BranchName = value
	}
	if value, ok := gcc.mutation.RepoName(); ok {
		_spec.SetField(gitcommit.FieldRepoName, field.TypeString, value)
		_node.RepoName = value
	}
	if value, ok := gcc.mutation.CommitMessage(); ok {
		_spec.SetField(gitcommit.FieldCommitMessage, field.TypeString, value)
		_node.CommitMessage = value
	}
	if value, ok := gcc.mutation.CommitTimestamp(); ok {
		_spec.SetField(gitcommit.FieldCommitTimestamp, field.TypeTime, value)
		_node.CommitTimestamp = value
	}
	if value, ok := gcc.mutation.Author(); ok {
		_spec.SetField(gitcommit.FieldAuthor, field.TypeString, value)
		_node.Author = value
	}
	if value, ok := gcc.mutation.Timestamp(); ok {
		_spec.SetField(gitcommit.FieldTimestamp, field.TypeTime, value)
		_node.Timestamp = value
	}
	if value, ok := gcc.mutation.PrNumber(); ok {
		_spec.SetField(gitcommit.FieldPrNumber, field.TypeString, value)
		_node.PrNumber = value
	}
	if nodes := gcc.mutation.ResultsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   gitcommit.ResultsTable,
			Columns: []string{gitcommit.ResultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(ciworkflowresult.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_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.GitCommit.Create().
//		SetCreateTime(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.GitCommitUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (gcc *GitCommitCreate) OnConflict(opts ...sql.ConflictOption) *GitCommitUpsertOne {
	gcc.conflict = opts
	return &GitCommitUpsertOne{
		create: gcc,
	}
}

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

type (
	// GitCommitUpsertOne is the builder for "upsert"-ing
	//  one GitCommit node.
	GitCommitUpsertOne struct {
		create *GitCommitCreate
	}

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

// SetUpdateTime sets the "update_time" field.
func (u *GitCommitUpsert) SetUpdateTime(v time.Time) *GitCommitUpsert {
	u.Set(gitcommit.FieldUpdateTime, v)
	return u
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateUpdateTime() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldUpdateTime)
	return u
}

// SetCommitHash sets the "commit_hash" field.
func (u *GitCommitUpsert) SetCommitHash(v string) *GitCommitUpsert {
	u.Set(gitcommit.FieldCommitHash, v)
	return u
}

// UpdateCommitHash sets the "commit_hash" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateCommitHash() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldCommitHash)
	return u
}

// SetBranchName sets the "branch_name" field.
func (u *GitCommitUpsert) SetBranchName(v string) *GitCommitUpsert {
	u.Set(gitcommit.FieldBranchName, v)
	return u
}

// UpdateBranchName sets the "branch_name" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateBranchName() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldBranchName)
	return u
}

// SetRepoName sets the "repo_name" field.
func (u *GitCommitUpsert) SetRepoName(v string) *GitCommitUpsert {
	u.Set(gitcommit.FieldRepoName, v)
	return u
}

// UpdateRepoName sets the "repo_name" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateRepoName() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldRepoName)
	return u
}

// SetCommitMessage sets the "commit_message" field.
func (u *GitCommitUpsert) SetCommitMessage(v string) *GitCommitUpsert {
	u.Set(gitcommit.FieldCommitMessage, v)
	return u
}

// UpdateCommitMessage sets the "commit_message" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateCommitMessage() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldCommitMessage)
	return u
}

// SetCommitTimestamp sets the "commit_timestamp" field.
func (u *GitCommitUpsert) SetCommitTimestamp(v time.Time) *GitCommitUpsert {
	u.Set(gitcommit.FieldCommitTimestamp, v)
	return u
}

// UpdateCommitTimestamp sets the "commit_timestamp" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateCommitTimestamp() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldCommitTimestamp)
	return u
}

// SetAuthor sets the "author" field.
func (u *GitCommitUpsert) SetAuthor(v string) *GitCommitUpsert {
	u.Set(gitcommit.FieldAuthor, v)
	return u
}

// UpdateAuthor sets the "author" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateAuthor() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldAuthor)
	return u
}

// ClearAuthor clears the value of the "author" field.
func (u *GitCommitUpsert) ClearAuthor() *GitCommitUpsert {
	u.SetNull(gitcommit.FieldAuthor)
	return u
}

// SetTimestamp sets the "timestamp" field.
func (u *GitCommitUpsert) SetTimestamp(v time.Time) *GitCommitUpsert {
	u.Set(gitcommit.FieldTimestamp, v)
	return u
}

// UpdateTimestamp sets the "timestamp" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdateTimestamp() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldTimestamp)
	return u
}

// ClearTimestamp clears the value of the "timestamp" field.
func (u *GitCommitUpsert) ClearTimestamp() *GitCommitUpsert {
	u.SetNull(gitcommit.FieldTimestamp)
	return u
}

// SetPrNumber sets the "pr_number" field.
func (u *GitCommitUpsert) SetPrNumber(v string) *GitCommitUpsert {
	u.Set(gitcommit.FieldPrNumber, v)
	return u
}

// UpdatePrNumber sets the "pr_number" field to the value that was provided on create.
func (u *GitCommitUpsert) UpdatePrNumber() *GitCommitUpsert {
	u.SetExcluded(gitcommit.FieldPrNumber)
	return u
}

// ClearPrNumber clears the value of the "pr_number" field.
func (u *GitCommitUpsert) ClearPrNumber() *GitCommitUpsert {
	u.SetNull(gitcommit.FieldPrNumber)
	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.GitCommit.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(gitcommit.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *GitCommitUpsertOne) UpdateNewValues() *GitCommitUpsertOne {
	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(gitcommit.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(gitcommit.FieldCreateTime)
		}
	}))
	return u
}

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

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

// SetUpdateTime sets the "update_time" field.
func (u *GitCommitUpsertOne) SetUpdateTime(v time.Time) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetUpdateTime(v)
	})
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateUpdateTime() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateUpdateTime()
	})
}

// SetCommitHash sets the "commit_hash" field.
func (u *GitCommitUpsertOne) SetCommitHash(v string) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetCommitHash(v)
	})
}

// UpdateCommitHash sets the "commit_hash" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateCommitHash() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateCommitHash()
	})
}

// SetBranchName sets the "branch_name" field.
func (u *GitCommitUpsertOne) SetBranchName(v string) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetBranchName(v)
	})
}

// UpdateBranchName sets the "branch_name" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateBranchName() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateBranchName()
	})
}

// SetRepoName sets the "repo_name" field.
func (u *GitCommitUpsertOne) SetRepoName(v string) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetRepoName(v)
	})
}

// UpdateRepoName sets the "repo_name" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateRepoName() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateRepoName()
	})
}

// SetCommitMessage sets the "commit_message" field.
func (u *GitCommitUpsertOne) SetCommitMessage(v string) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetCommitMessage(v)
	})
}

// UpdateCommitMessage sets the "commit_message" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateCommitMessage() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateCommitMessage()
	})
}

// SetCommitTimestamp sets the "commit_timestamp" field.
func (u *GitCommitUpsertOne) SetCommitTimestamp(v time.Time) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetCommitTimestamp(v)
	})
}

// UpdateCommitTimestamp sets the "commit_timestamp" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateCommitTimestamp() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateCommitTimestamp()
	})
}

// SetAuthor sets the "author" field.
func (u *GitCommitUpsertOne) SetAuthor(v string) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetAuthor(v)
	})
}

// UpdateAuthor sets the "author" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateAuthor() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateAuthor()
	})
}

// ClearAuthor clears the value of the "author" field.
func (u *GitCommitUpsertOne) ClearAuthor() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.ClearAuthor()
	})
}

// SetTimestamp sets the "timestamp" field.
func (u *GitCommitUpsertOne) SetTimestamp(v time.Time) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetTimestamp(v)
	})
}

// UpdateTimestamp sets the "timestamp" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdateTimestamp() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateTimestamp()
	})
}

// ClearTimestamp clears the value of the "timestamp" field.
func (u *GitCommitUpsertOne) ClearTimestamp() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.ClearTimestamp()
	})
}

// SetPrNumber sets the "pr_number" field.
func (u *GitCommitUpsertOne) SetPrNumber(v string) *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetPrNumber(v)
	})
}

// UpdatePrNumber sets the "pr_number" field to the value that was provided on create.
func (u *GitCommitUpsertOne) UpdatePrNumber() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdatePrNumber()
	})
}

// ClearPrNumber clears the value of the "pr_number" field.
func (u *GitCommitUpsertOne) ClearPrNumber() *GitCommitUpsertOne {
	return u.Update(func(s *GitCommitUpsert) {
		s.ClearPrNumber()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *GitCommitUpsertOne) 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 *GitCommitUpsertOne) 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: GitCommitUpsertOne.ID is not supported by MySQL driver. Use GitCommitUpsertOne.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 *GitCommitUpsertOne) IDX(ctx context.Context) uuid.UUID {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.GitCommit.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.GitCommitUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (gccb *GitCommitCreateBulk) OnConflict(opts ...sql.ConflictOption) *GitCommitUpsertBulk {
	gccb.conflict = opts
	return &GitCommitUpsertBulk{
		create: gccb,
	}
}

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

// GitCommitUpsertBulk is the builder for "upsert"-ing
// a bulk of GitCommit nodes.
type GitCommitUpsertBulk struct {
	create *GitCommitCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.GitCommit.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(gitcommit.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *GitCommitUpsertBulk) UpdateNewValues() *GitCommitUpsertBulk {
	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(gitcommit.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(gitcommit.FieldCreateTime)
			}
		}
	}))
	return u
}

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

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

// SetUpdateTime sets the "update_time" field.
func (u *GitCommitUpsertBulk) SetUpdateTime(v time.Time) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetUpdateTime(v)
	})
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateUpdateTime() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateUpdateTime()
	})
}

// SetCommitHash sets the "commit_hash" field.
func (u *GitCommitUpsertBulk) SetCommitHash(v string) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetCommitHash(v)
	})
}

// UpdateCommitHash sets the "commit_hash" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateCommitHash() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateCommitHash()
	})
}

// SetBranchName sets the "branch_name" field.
func (u *GitCommitUpsertBulk) SetBranchName(v string) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetBranchName(v)
	})
}

// UpdateBranchName sets the "branch_name" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateBranchName() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateBranchName()
	})
}

// SetRepoName sets the "repo_name" field.
func (u *GitCommitUpsertBulk) SetRepoName(v string) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetRepoName(v)
	})
}

// UpdateRepoName sets the "repo_name" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateRepoName() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateRepoName()
	})
}

// SetCommitMessage sets the "commit_message" field.
func (u *GitCommitUpsertBulk) SetCommitMessage(v string) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetCommitMessage(v)
	})
}

// UpdateCommitMessage sets the "commit_message" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateCommitMessage() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateCommitMessage()
	})
}

// SetCommitTimestamp sets the "commit_timestamp" field.
func (u *GitCommitUpsertBulk) SetCommitTimestamp(v time.Time) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetCommitTimestamp(v)
	})
}

// UpdateCommitTimestamp sets the "commit_timestamp" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateCommitTimestamp() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateCommitTimestamp()
	})
}

// SetAuthor sets the "author" field.
func (u *GitCommitUpsertBulk) SetAuthor(v string) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetAuthor(v)
	})
}

// UpdateAuthor sets the "author" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateAuthor() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateAuthor()
	})
}

// ClearAuthor clears the value of the "author" field.
func (u *GitCommitUpsertBulk) ClearAuthor() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.ClearAuthor()
	})
}

// SetTimestamp sets the "timestamp" field.
func (u *GitCommitUpsertBulk) SetTimestamp(v time.Time) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetTimestamp(v)
	})
}

// UpdateTimestamp sets the "timestamp" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdateTimestamp() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdateTimestamp()
	})
}

// ClearTimestamp clears the value of the "timestamp" field.
func (u *GitCommitUpsertBulk) ClearTimestamp() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.ClearTimestamp()
	})
}

// SetPrNumber sets the "pr_number" field.
func (u *GitCommitUpsertBulk) SetPrNumber(v string) *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.SetPrNumber(v)
	})
}

// UpdatePrNumber sets the "pr_number" field to the value that was provided on create.
func (u *GitCommitUpsertBulk) UpdatePrNumber() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.UpdatePrNumber()
	})
}

// ClearPrNumber clears the value of the "pr_number" field.
func (u *GitCommitUpsertBulk) ClearPrNumber() *GitCommitUpsertBulk {
	return u.Update(func(s *GitCommitUpsert) {
		s.ClearPrNumber()
	})
}

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

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