// 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/AvengeMedia/dankcalendar/core/ent/calendar"
	"github.com/AvengeMedia/dankcalendar/core/ent/task"
)

// TaskCreate is the builder for creating a Task entity.
type TaskCreate struct {
	config
	mutation *TaskMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetUID sets the "uid" field.
func (_c *TaskCreate) SetUID(v string) *TaskCreate {
	_c.mutation.SetUID(v)
	return _c
}

// SetRemoteID sets the "remote_id" field.
func (_c *TaskCreate) SetRemoteID(v string) *TaskCreate {
	_c.mutation.SetRemoteID(v)
	return _c
}

// SetNillableRemoteID sets the "remote_id" field if the given value is not nil.
func (_c *TaskCreate) SetNillableRemoteID(v *string) *TaskCreate {
	if v != nil {
		_c.SetRemoteID(*v)
	}
	return _c
}

// SetEtag sets the "etag" field.
func (_c *TaskCreate) SetEtag(v string) *TaskCreate {
	_c.mutation.SetEtag(v)
	return _c
}

// SetNillableEtag sets the "etag" field if the given value is not nil.
func (_c *TaskCreate) SetNillableEtag(v *string) *TaskCreate {
	if v != nil {
		_c.SetEtag(*v)
	}
	return _c
}

// SetSummary sets the "summary" field.
func (_c *TaskCreate) SetSummary(v string) *TaskCreate {
	_c.mutation.SetSummary(v)
	return _c
}

// SetDescription sets the "description" field.
func (_c *TaskCreate) SetDescription(v string) *TaskCreate {
	_c.mutation.SetDescription(v)
	return _c
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_c *TaskCreate) SetNillableDescription(v *string) *TaskCreate {
	if v != nil {
		_c.SetDescription(*v)
	}
	return _c
}

// SetLocation sets the "location" field.
func (_c *TaskCreate) SetLocation(v string) *TaskCreate {
	_c.mutation.SetLocation(v)
	return _c
}

// SetNillableLocation sets the "location" field if the given value is not nil.
func (_c *TaskCreate) SetNillableLocation(v *string) *TaskCreate {
	if v != nil {
		_c.SetLocation(*v)
	}
	return _c
}

// SetStatus sets the "status" field.
func (_c *TaskCreate) SetStatus(v task.Status) *TaskCreate {
	_c.mutation.SetStatus(v)
	return _c
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *TaskCreate) SetNillableStatus(v *task.Status) *TaskCreate {
	if v != nil {
		_c.SetStatus(*v)
	}
	return _c
}

// SetPriority sets the "priority" field.
func (_c *TaskCreate) SetPriority(v int) *TaskCreate {
	_c.mutation.SetPriority(v)
	return _c
}

// SetNillablePriority sets the "priority" field if the given value is not nil.
func (_c *TaskCreate) SetNillablePriority(v *int) *TaskCreate {
	if v != nil {
		_c.SetPriority(*v)
	}
	return _c
}

// SetPercentComplete sets the "percent_complete" field.
func (_c *TaskCreate) SetPercentComplete(v int) *TaskCreate {
	_c.mutation.SetPercentComplete(v)
	return _c
}

// SetNillablePercentComplete sets the "percent_complete" field if the given value is not nil.
func (_c *TaskCreate) SetNillablePercentComplete(v *int) *TaskCreate {
	if v != nil {
		_c.SetPercentComplete(*v)
	}
	return _c
}

// SetDue sets the "due" field.
func (_c *TaskCreate) SetDue(v time.Time) *TaskCreate {
	_c.mutation.SetDue(v)
	return _c
}

// SetNillableDue sets the "due" field if the given value is not nil.
func (_c *TaskCreate) SetNillableDue(v *time.Time) *TaskCreate {
	if v != nil {
		_c.SetDue(*v)
	}
	return _c
}

// SetStart sets the "start" field.
func (_c *TaskCreate) SetStart(v time.Time) *TaskCreate {
	_c.mutation.SetStart(v)
	return _c
}

// SetNillableStart sets the "start" field if the given value is not nil.
func (_c *TaskCreate) SetNillableStart(v *time.Time) *TaskCreate {
	if v != nil {
		_c.SetStart(*v)
	}
	return _c
}

// SetCompleted sets the "completed" field.
func (_c *TaskCreate) SetCompleted(v time.Time) *TaskCreate {
	_c.mutation.SetCompleted(v)
	return _c
}

// SetNillableCompleted sets the "completed" field if the given value is not nil.
func (_c *TaskCreate) SetNillableCompleted(v *time.Time) *TaskCreate {
	if v != nil {
		_c.SetCompleted(*v)
	}
	return _c
}

// SetAllDay sets the "all_day" field.
func (_c *TaskCreate) SetAllDay(v bool) *TaskCreate {
	_c.mutation.SetAllDay(v)
	return _c
}

// SetNillableAllDay sets the "all_day" field if the given value is not nil.
func (_c *TaskCreate) SetNillableAllDay(v *bool) *TaskCreate {
	if v != nil {
		_c.SetAllDay(*v)
	}
	return _c
}

// SetDueTz sets the "due_tz" field.
func (_c *TaskCreate) SetDueTz(v string) *TaskCreate {
	_c.mutation.SetDueTz(v)
	return _c
}

// SetNillableDueTz sets the "due_tz" field if the given value is not nil.
func (_c *TaskCreate) SetNillableDueTz(v *string) *TaskCreate {
	if v != nil {
		_c.SetDueTz(*v)
	}
	return _c
}

// SetStartTz sets the "start_tz" field.
func (_c *TaskCreate) SetStartTz(v string) *TaskCreate {
	_c.mutation.SetStartTz(v)
	return _c
}

// SetNillableStartTz sets the "start_tz" field if the given value is not nil.
func (_c *TaskCreate) SetNillableStartTz(v *string) *TaskCreate {
	if v != nil {
		_c.SetStartTz(*v)
	}
	return _c
}

// SetParentUID sets the "parent_uid" field.
func (_c *TaskCreate) SetParentUID(v string) *TaskCreate {
	_c.mutation.SetParentUID(v)
	return _c
}

// SetNillableParentUID sets the "parent_uid" field if the given value is not nil.
func (_c *TaskCreate) SetNillableParentUID(v *string) *TaskCreate {
	if v != nil {
		_c.SetParentUID(*v)
	}
	return _c
}

// SetRecurrence sets the "recurrence" field.
func (_c *TaskCreate) SetRecurrence(v map[string]interface{}) *TaskCreate {
	_c.mutation.SetRecurrence(v)
	return _c
}

// SetReminders sets the "reminders" field.
func (_c *TaskCreate) SetReminders(v []map[string]interface{}) *TaskCreate {
	_c.mutation.SetReminders(v)
	return _c
}

// SetCategories sets the "categories" field.
func (_c *TaskCreate) SetCategories(v []string) *TaskCreate {
	_c.mutation.SetCategories(v)
	return _c
}

// SetRawIcs sets the "raw_ics" field.
func (_c *TaskCreate) SetRawIcs(v string) *TaskCreate {
	_c.mutation.SetRawIcs(v)
	return _c
}

// SetNillableRawIcs sets the "raw_ics" field if the given value is not nil.
func (_c *TaskCreate) SetNillableRawIcs(v *string) *TaskCreate {
	if v != nil {
		_c.SetRawIcs(*v)
	}
	return _c
}

// SetCreated sets the "created" field.
func (_c *TaskCreate) SetCreated(v time.Time) *TaskCreate {
	_c.mutation.SetCreated(v)
	return _c
}

// SetNillableCreated sets the "created" field if the given value is not nil.
func (_c *TaskCreate) SetNillableCreated(v *time.Time) *TaskCreate {
	if v != nil {
		_c.SetCreated(*v)
	}
	return _c
}

// SetUpdated sets the "updated" field.
func (_c *TaskCreate) SetUpdated(v time.Time) *TaskCreate {
	_c.mutation.SetUpdated(v)
	return _c
}

// SetNillableUpdated sets the "updated" field if the given value is not nil.
func (_c *TaskCreate) SetNillableUpdated(v *time.Time) *TaskCreate {
	if v != nil {
		_c.SetUpdated(*v)
	}
	return _c
}

// SetID sets the "id" field.
func (_c *TaskCreate) SetID(v string) *TaskCreate {
	_c.mutation.SetID(v)
	return _c
}

// SetCalendarID sets the "calendar" edge to the Calendar entity by ID.
func (_c *TaskCreate) SetCalendarID(id string) *TaskCreate {
	_c.mutation.SetCalendarID(id)
	return _c
}

// SetCalendar sets the "calendar" edge to the Calendar entity.
func (_c *TaskCreate) SetCalendar(v *Calendar) *TaskCreate {
	return _c.SetCalendarID(v.ID)
}

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

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

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

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

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

// defaults sets the default values of the builder before save.
func (_c *TaskCreate) defaults() {
	if _, ok := _c.mutation.Status(); !ok {
		v := task.DefaultStatus
		_c.mutation.SetStatus(v)
	}
	if _, ok := _c.mutation.Priority(); !ok {
		v := task.DefaultPriority
		_c.mutation.SetPriority(v)
	}
	if _, ok := _c.mutation.PercentComplete(); !ok {
		v := task.DefaultPercentComplete
		_c.mutation.SetPercentComplete(v)
	}
	if _, ok := _c.mutation.AllDay(); !ok {
		v := task.DefaultAllDay
		_c.mutation.SetAllDay(v)
	}
	if _, ok := _c.mutation.Created(); !ok {
		v := task.DefaultCreated()
		_c.mutation.SetCreated(v)
	}
	if _, ok := _c.mutation.Updated(); !ok {
		v := task.DefaultUpdated()
		_c.mutation.SetUpdated(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_c *TaskCreate) check() error {
	if _, ok := _c.mutation.UID(); !ok {
		return &ValidationError{Name: "uid", err: errors.New(`ent: missing required field "Task.uid"`)}
	}
	if v, ok := _c.mutation.UID(); ok {
		if err := task.UIDValidator(v); err != nil {
			return &ValidationError{Name: "uid", err: fmt.Errorf(`ent: validator failed for field "Task.uid": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Summary(); !ok {
		return &ValidationError{Name: "summary", err: errors.New(`ent: missing required field "Task.summary"`)}
	}
	if _, ok := _c.mutation.Status(); !ok {
		return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Task.status"`)}
	}
	if v, ok := _c.mutation.Status(); ok {
		if err := task.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Task.status": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Priority(); !ok {
		return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "Task.priority"`)}
	}
	if _, ok := _c.mutation.PercentComplete(); !ok {
		return &ValidationError{Name: "percent_complete", err: errors.New(`ent: missing required field "Task.percent_complete"`)}
	}
	if _, ok := _c.mutation.AllDay(); !ok {
		return &ValidationError{Name: "all_day", err: errors.New(`ent: missing required field "Task.all_day"`)}
	}
	if _, ok := _c.mutation.Created(); !ok {
		return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Task.created"`)}
	}
	if _, ok := _c.mutation.Updated(); !ok {
		return &ValidationError{Name: "updated", err: errors.New(`ent: missing required field "Task.updated"`)}
	}
	if v, ok := _c.mutation.ID(); ok {
		if err := task.IDValidator(v); err != nil {
			return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Task.id": %w`, err)}
		}
	}
	if len(_c.mutation.CalendarIDs()) == 0 {
		return &ValidationError{Name: "calendar", err: errors.New(`ent: missing required edge "Task.calendar"`)}
	}
	return nil
}

func (_c *TaskCreate) sqlSave(ctx context.Context) (*Task, error) {
	if err := _c.check(); err != nil {
		return nil, err
	}
	_node, _spec := _c.createSpec()
	if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != nil {
		if id, ok := _spec.ID.Value.(string); ok {
			_node.ID = id
		} else {
			return nil, fmt.Errorf("unexpected Task.ID type: %T", _spec.ID.Value)
		}
	}
	_c.mutation.id = &_node.ID
	_c.mutation.done = true
	return _node, nil
}

func (_c *TaskCreate) createSpec() (*Task, *sqlgraph.CreateSpec) {
	var (
		_node = &Task{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(task.Table, sqlgraph.NewFieldSpec(task.FieldID, field.TypeString))
	)
	_spec.OnConflict = _c.conflict
	if id, ok := _c.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := _c.mutation.UID(); ok {
		_spec.SetField(task.FieldUID, field.TypeString, value)
		_node.UID = value
	}
	if value, ok := _c.mutation.RemoteID(); ok {
		_spec.SetField(task.FieldRemoteID, field.TypeString, value)
		_node.RemoteID = value
	}
	if value, ok := _c.mutation.Etag(); ok {
		_spec.SetField(task.FieldEtag, field.TypeString, value)
		_node.Etag = value
	}
	if value, ok := _c.mutation.Summary(); ok {
		_spec.SetField(task.FieldSummary, field.TypeString, value)
		_node.Summary = value
	}
	if value, ok := _c.mutation.Description(); ok {
		_spec.SetField(task.FieldDescription, field.TypeString, value)
		_node.Description = value
	}
	if value, ok := _c.mutation.Location(); ok {
		_spec.SetField(task.FieldLocation, field.TypeString, value)
		_node.Location = value
	}
	if value, ok := _c.mutation.Status(); ok {
		_spec.SetField(task.FieldStatus, field.TypeEnum, value)
		_node.Status = value
	}
	if value, ok := _c.mutation.Priority(); ok {
		_spec.SetField(task.FieldPriority, field.TypeInt, value)
		_node.Priority = value
	}
	if value, ok := _c.mutation.PercentComplete(); ok {
		_spec.SetField(task.FieldPercentComplete, field.TypeInt, value)
		_node.PercentComplete = value
	}
	if value, ok := _c.mutation.Due(); ok {
		_spec.SetField(task.FieldDue, field.TypeTime, value)
		_node.Due = &value
	}
	if value, ok := _c.mutation.Start(); ok {
		_spec.SetField(task.FieldStart, field.TypeTime, value)
		_node.Start = &value
	}
	if value, ok := _c.mutation.Completed(); ok {
		_spec.SetField(task.FieldCompleted, field.TypeTime, value)
		_node.Completed = &value
	}
	if value, ok := _c.mutation.AllDay(); ok {
		_spec.SetField(task.FieldAllDay, field.TypeBool, value)
		_node.AllDay = value
	}
	if value, ok := _c.mutation.DueTz(); ok {
		_spec.SetField(task.FieldDueTz, field.TypeString, value)
		_node.DueTz = value
	}
	if value, ok := _c.mutation.StartTz(); ok {
		_spec.SetField(task.FieldStartTz, field.TypeString, value)
		_node.StartTz = value
	}
	if value, ok := _c.mutation.ParentUID(); ok {
		_spec.SetField(task.FieldParentUID, field.TypeString, value)
		_node.ParentUID = value
	}
	if value, ok := _c.mutation.Recurrence(); ok {
		_spec.SetField(task.FieldRecurrence, field.TypeJSON, value)
		_node.Recurrence = value
	}
	if value, ok := _c.mutation.Reminders(); ok {
		_spec.SetField(task.FieldReminders, field.TypeJSON, value)
		_node.Reminders = value
	}
	if value, ok := _c.mutation.Categories(); ok {
		_spec.SetField(task.FieldCategories, field.TypeJSON, value)
		_node.Categories = value
	}
	if value, ok := _c.mutation.RawIcs(); ok {
		_spec.SetField(task.FieldRawIcs, field.TypeString, value)
		_node.RawIcs = value
	}
	if value, ok := _c.mutation.Created(); ok {
		_spec.SetField(task.FieldCreated, field.TypeTime, value)
		_node.Created = value
	}
	if value, ok := _c.mutation.Updated(); ok {
		_spec.SetField(task.FieldUpdated, field.TypeTime, value)
		_node.Updated = value
	}
	if nodes := _c.mutation.CalendarIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   task.CalendarTable,
			Columns: []string{task.CalendarColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(calendar.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.calendar_tasks = &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.Task.Create().
//		SetUID(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.TaskUpsert) {
//			SetUID(v+v).
//		}).
//		Exec(ctx)
func (_c *TaskCreate) OnConflict(opts ...sql.ConflictOption) *TaskUpsertOne {
	_c.conflict = opts
	return &TaskUpsertOne{
		create: _c,
	}
}

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

type (
	// TaskUpsertOne is the builder for "upsert"-ing
	//  one Task node.
	TaskUpsertOne struct {
		create *TaskCreate
	}

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

// SetUID sets the "uid" field.
func (u *TaskUpsert) SetUID(v string) *TaskUpsert {
	u.Set(task.FieldUID, v)
	return u
}

// UpdateUID sets the "uid" field to the value that was provided on create.
func (u *TaskUpsert) UpdateUID() *TaskUpsert {
	u.SetExcluded(task.FieldUID)
	return u
}

// SetRemoteID sets the "remote_id" field.
func (u *TaskUpsert) SetRemoteID(v string) *TaskUpsert {
	u.Set(task.FieldRemoteID, v)
	return u
}

// UpdateRemoteID sets the "remote_id" field to the value that was provided on create.
func (u *TaskUpsert) UpdateRemoteID() *TaskUpsert {
	u.SetExcluded(task.FieldRemoteID)
	return u
}

// ClearRemoteID clears the value of the "remote_id" field.
func (u *TaskUpsert) ClearRemoteID() *TaskUpsert {
	u.SetNull(task.FieldRemoteID)
	return u
}

// SetEtag sets the "etag" field.
func (u *TaskUpsert) SetEtag(v string) *TaskUpsert {
	u.Set(task.FieldEtag, v)
	return u
}

// UpdateEtag sets the "etag" field to the value that was provided on create.
func (u *TaskUpsert) UpdateEtag() *TaskUpsert {
	u.SetExcluded(task.FieldEtag)
	return u
}

// ClearEtag clears the value of the "etag" field.
func (u *TaskUpsert) ClearEtag() *TaskUpsert {
	u.SetNull(task.FieldEtag)
	return u
}

// SetSummary sets the "summary" field.
func (u *TaskUpsert) SetSummary(v string) *TaskUpsert {
	u.Set(task.FieldSummary, v)
	return u
}

// UpdateSummary sets the "summary" field to the value that was provided on create.
func (u *TaskUpsert) UpdateSummary() *TaskUpsert {
	u.SetExcluded(task.FieldSummary)
	return u
}

// SetDescription sets the "description" field.
func (u *TaskUpsert) SetDescription(v string) *TaskUpsert {
	u.Set(task.FieldDescription, v)
	return u
}

// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *TaskUpsert) UpdateDescription() *TaskUpsert {
	u.SetExcluded(task.FieldDescription)
	return u
}

// ClearDescription clears the value of the "description" field.
func (u *TaskUpsert) ClearDescription() *TaskUpsert {
	u.SetNull(task.FieldDescription)
	return u
}

// SetLocation sets the "location" field.
func (u *TaskUpsert) SetLocation(v string) *TaskUpsert {
	u.Set(task.FieldLocation, v)
	return u
}

// UpdateLocation sets the "location" field to the value that was provided on create.
func (u *TaskUpsert) UpdateLocation() *TaskUpsert {
	u.SetExcluded(task.FieldLocation)
	return u
}

// ClearLocation clears the value of the "location" field.
func (u *TaskUpsert) ClearLocation() *TaskUpsert {
	u.SetNull(task.FieldLocation)
	return u
}

// SetStatus sets the "status" field.
func (u *TaskUpsert) SetStatus(v task.Status) *TaskUpsert {
	u.Set(task.FieldStatus, v)
	return u
}

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

// SetPriority sets the "priority" field.
func (u *TaskUpsert) SetPriority(v int) *TaskUpsert {
	u.Set(task.FieldPriority, v)
	return u
}

// UpdatePriority sets the "priority" field to the value that was provided on create.
func (u *TaskUpsert) UpdatePriority() *TaskUpsert {
	u.SetExcluded(task.FieldPriority)
	return u
}

// AddPriority adds v to the "priority" field.
func (u *TaskUpsert) AddPriority(v int) *TaskUpsert {
	u.Add(task.FieldPriority, v)
	return u
}

// SetPercentComplete sets the "percent_complete" field.
func (u *TaskUpsert) SetPercentComplete(v int) *TaskUpsert {
	u.Set(task.FieldPercentComplete, v)
	return u
}

// UpdatePercentComplete sets the "percent_complete" field to the value that was provided on create.
func (u *TaskUpsert) UpdatePercentComplete() *TaskUpsert {
	u.SetExcluded(task.FieldPercentComplete)
	return u
}

// AddPercentComplete adds v to the "percent_complete" field.
func (u *TaskUpsert) AddPercentComplete(v int) *TaskUpsert {
	u.Add(task.FieldPercentComplete, v)
	return u
}

// SetDue sets the "due" field.
func (u *TaskUpsert) SetDue(v time.Time) *TaskUpsert {
	u.Set(task.FieldDue, v)
	return u
}

// UpdateDue sets the "due" field to the value that was provided on create.
func (u *TaskUpsert) UpdateDue() *TaskUpsert {
	u.SetExcluded(task.FieldDue)
	return u
}

// ClearDue clears the value of the "due" field.
func (u *TaskUpsert) ClearDue() *TaskUpsert {
	u.SetNull(task.FieldDue)
	return u
}

// SetStart sets the "start" field.
func (u *TaskUpsert) SetStart(v time.Time) *TaskUpsert {
	u.Set(task.FieldStart, v)
	return u
}

// UpdateStart sets the "start" field to the value that was provided on create.
func (u *TaskUpsert) UpdateStart() *TaskUpsert {
	u.SetExcluded(task.FieldStart)
	return u
}

// ClearStart clears the value of the "start" field.
func (u *TaskUpsert) ClearStart() *TaskUpsert {
	u.SetNull(task.FieldStart)
	return u
}

// SetCompleted sets the "completed" field.
func (u *TaskUpsert) SetCompleted(v time.Time) *TaskUpsert {
	u.Set(task.FieldCompleted, v)
	return u
}

// UpdateCompleted sets the "completed" field to the value that was provided on create.
func (u *TaskUpsert) UpdateCompleted() *TaskUpsert {
	u.SetExcluded(task.FieldCompleted)
	return u
}

// ClearCompleted clears the value of the "completed" field.
func (u *TaskUpsert) ClearCompleted() *TaskUpsert {
	u.SetNull(task.FieldCompleted)
	return u
}

// SetAllDay sets the "all_day" field.
func (u *TaskUpsert) SetAllDay(v bool) *TaskUpsert {
	u.Set(task.FieldAllDay, v)
	return u
}

// UpdateAllDay sets the "all_day" field to the value that was provided on create.
func (u *TaskUpsert) UpdateAllDay() *TaskUpsert {
	u.SetExcluded(task.FieldAllDay)
	return u
}

// SetDueTz sets the "due_tz" field.
func (u *TaskUpsert) SetDueTz(v string) *TaskUpsert {
	u.Set(task.FieldDueTz, v)
	return u
}

// UpdateDueTz sets the "due_tz" field to the value that was provided on create.
func (u *TaskUpsert) UpdateDueTz() *TaskUpsert {
	u.SetExcluded(task.FieldDueTz)
	return u
}

// ClearDueTz clears the value of the "due_tz" field.
func (u *TaskUpsert) ClearDueTz() *TaskUpsert {
	u.SetNull(task.FieldDueTz)
	return u
}

// SetStartTz sets the "start_tz" field.
func (u *TaskUpsert) SetStartTz(v string) *TaskUpsert {
	u.Set(task.FieldStartTz, v)
	return u
}

// UpdateStartTz sets the "start_tz" field to the value that was provided on create.
func (u *TaskUpsert) UpdateStartTz() *TaskUpsert {
	u.SetExcluded(task.FieldStartTz)
	return u
}

// ClearStartTz clears the value of the "start_tz" field.
func (u *TaskUpsert) ClearStartTz() *TaskUpsert {
	u.SetNull(task.FieldStartTz)
	return u
}

// SetParentUID sets the "parent_uid" field.
func (u *TaskUpsert) SetParentUID(v string) *TaskUpsert {
	u.Set(task.FieldParentUID, v)
	return u
}

// UpdateParentUID sets the "parent_uid" field to the value that was provided on create.
func (u *TaskUpsert) UpdateParentUID() *TaskUpsert {
	u.SetExcluded(task.FieldParentUID)
	return u
}

// ClearParentUID clears the value of the "parent_uid" field.
func (u *TaskUpsert) ClearParentUID() *TaskUpsert {
	u.SetNull(task.FieldParentUID)
	return u
}

// SetRecurrence sets the "recurrence" field.
func (u *TaskUpsert) SetRecurrence(v map[string]interface{}) *TaskUpsert {
	u.Set(task.FieldRecurrence, v)
	return u
}

// UpdateRecurrence sets the "recurrence" field to the value that was provided on create.
func (u *TaskUpsert) UpdateRecurrence() *TaskUpsert {
	u.SetExcluded(task.FieldRecurrence)
	return u
}

// ClearRecurrence clears the value of the "recurrence" field.
func (u *TaskUpsert) ClearRecurrence() *TaskUpsert {
	u.SetNull(task.FieldRecurrence)
	return u
}

// SetReminders sets the "reminders" field.
func (u *TaskUpsert) SetReminders(v []map[string]interface{}) *TaskUpsert {
	u.Set(task.FieldReminders, v)
	return u
}

// UpdateReminders sets the "reminders" field to the value that was provided on create.
func (u *TaskUpsert) UpdateReminders() *TaskUpsert {
	u.SetExcluded(task.FieldReminders)
	return u
}

// ClearReminders clears the value of the "reminders" field.
func (u *TaskUpsert) ClearReminders() *TaskUpsert {
	u.SetNull(task.FieldReminders)
	return u
}

// SetCategories sets the "categories" field.
func (u *TaskUpsert) SetCategories(v []string) *TaskUpsert {
	u.Set(task.FieldCategories, v)
	return u
}

// UpdateCategories sets the "categories" field to the value that was provided on create.
func (u *TaskUpsert) UpdateCategories() *TaskUpsert {
	u.SetExcluded(task.FieldCategories)
	return u
}

// ClearCategories clears the value of the "categories" field.
func (u *TaskUpsert) ClearCategories() *TaskUpsert {
	u.SetNull(task.FieldCategories)
	return u
}

// SetRawIcs sets the "raw_ics" field.
func (u *TaskUpsert) SetRawIcs(v string) *TaskUpsert {
	u.Set(task.FieldRawIcs, v)
	return u
}

// UpdateRawIcs sets the "raw_ics" field to the value that was provided on create.
func (u *TaskUpsert) UpdateRawIcs() *TaskUpsert {
	u.SetExcluded(task.FieldRawIcs)
	return u
}

// ClearRawIcs clears the value of the "raw_ics" field.
func (u *TaskUpsert) ClearRawIcs() *TaskUpsert {
	u.SetNull(task.FieldRawIcs)
	return u
}

// SetCreated sets the "created" field.
func (u *TaskUpsert) SetCreated(v time.Time) *TaskUpsert {
	u.Set(task.FieldCreated, v)
	return u
}

// UpdateCreated sets the "created" field to the value that was provided on create.
func (u *TaskUpsert) UpdateCreated() *TaskUpsert {
	u.SetExcluded(task.FieldCreated)
	return u
}

// SetUpdated sets the "updated" field.
func (u *TaskUpsert) SetUpdated(v time.Time) *TaskUpsert {
	u.Set(task.FieldUpdated, v)
	return u
}

// UpdateUpdated sets the "updated" field to the value that was provided on create.
func (u *TaskUpsert) UpdateUpdated() *TaskUpsert {
	u.SetExcluded(task.FieldUpdated)
	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.Task.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(task.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *TaskUpsertOne) UpdateNewValues() *TaskUpsertOne {
	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(task.FieldID)
		}
	}))
	return u
}

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

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

// SetUID sets the "uid" field.
func (u *TaskUpsertOne) SetUID(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetUID(v)
	})
}

// UpdateUID sets the "uid" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateUID() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateUID()
	})
}

// SetRemoteID sets the "remote_id" field.
func (u *TaskUpsertOne) SetRemoteID(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetRemoteID(v)
	})
}

// UpdateRemoteID sets the "remote_id" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateRemoteID() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateRemoteID()
	})
}

// ClearRemoteID clears the value of the "remote_id" field.
func (u *TaskUpsertOne) ClearRemoteID() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearRemoteID()
	})
}

// SetEtag sets the "etag" field.
func (u *TaskUpsertOne) SetEtag(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetEtag(v)
	})
}

// UpdateEtag sets the "etag" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateEtag() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateEtag()
	})
}

// ClearEtag clears the value of the "etag" field.
func (u *TaskUpsertOne) ClearEtag() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearEtag()
	})
}

// SetSummary sets the "summary" field.
func (u *TaskUpsertOne) SetSummary(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetSummary(v)
	})
}

// UpdateSummary sets the "summary" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateSummary() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateSummary()
	})
}

// SetDescription sets the "description" field.
func (u *TaskUpsertOne) SetDescription(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetDescription(v)
	})
}

// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateDescription() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateDescription()
	})
}

// ClearDescription clears the value of the "description" field.
func (u *TaskUpsertOne) ClearDescription() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearDescription()
	})
}

// SetLocation sets the "location" field.
func (u *TaskUpsertOne) SetLocation(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetLocation(v)
	})
}

// UpdateLocation sets the "location" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateLocation() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateLocation()
	})
}

// ClearLocation clears the value of the "location" field.
func (u *TaskUpsertOne) ClearLocation() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearLocation()
	})
}

// SetStatus sets the "status" field.
func (u *TaskUpsertOne) SetStatus(v task.Status) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetStatus(v)
	})
}

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

// SetPriority sets the "priority" field.
func (u *TaskUpsertOne) SetPriority(v int) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetPriority(v)
	})
}

// AddPriority adds v to the "priority" field.
func (u *TaskUpsertOne) AddPriority(v int) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.AddPriority(v)
	})
}

// UpdatePriority sets the "priority" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdatePriority() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdatePriority()
	})
}

// SetPercentComplete sets the "percent_complete" field.
func (u *TaskUpsertOne) SetPercentComplete(v int) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetPercentComplete(v)
	})
}

// AddPercentComplete adds v to the "percent_complete" field.
func (u *TaskUpsertOne) AddPercentComplete(v int) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.AddPercentComplete(v)
	})
}

// UpdatePercentComplete sets the "percent_complete" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdatePercentComplete() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdatePercentComplete()
	})
}

// SetDue sets the "due" field.
func (u *TaskUpsertOne) SetDue(v time.Time) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetDue(v)
	})
}

// UpdateDue sets the "due" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateDue() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateDue()
	})
}

// ClearDue clears the value of the "due" field.
func (u *TaskUpsertOne) ClearDue() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearDue()
	})
}

// SetStart sets the "start" field.
func (u *TaskUpsertOne) SetStart(v time.Time) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetStart(v)
	})
}

// UpdateStart sets the "start" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateStart() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateStart()
	})
}

// ClearStart clears the value of the "start" field.
func (u *TaskUpsertOne) ClearStart() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearStart()
	})
}

// SetCompleted sets the "completed" field.
func (u *TaskUpsertOne) SetCompleted(v time.Time) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetCompleted(v)
	})
}

// UpdateCompleted sets the "completed" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateCompleted() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateCompleted()
	})
}

// ClearCompleted clears the value of the "completed" field.
func (u *TaskUpsertOne) ClearCompleted() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearCompleted()
	})
}

// SetAllDay sets the "all_day" field.
func (u *TaskUpsertOne) SetAllDay(v bool) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetAllDay(v)
	})
}

// UpdateAllDay sets the "all_day" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateAllDay() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateAllDay()
	})
}

// SetDueTz sets the "due_tz" field.
func (u *TaskUpsertOne) SetDueTz(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetDueTz(v)
	})
}

// UpdateDueTz sets the "due_tz" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateDueTz() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateDueTz()
	})
}

// ClearDueTz clears the value of the "due_tz" field.
func (u *TaskUpsertOne) ClearDueTz() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearDueTz()
	})
}

// SetStartTz sets the "start_tz" field.
func (u *TaskUpsertOne) SetStartTz(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetStartTz(v)
	})
}

// UpdateStartTz sets the "start_tz" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateStartTz() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateStartTz()
	})
}

// ClearStartTz clears the value of the "start_tz" field.
func (u *TaskUpsertOne) ClearStartTz() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearStartTz()
	})
}

// SetParentUID sets the "parent_uid" field.
func (u *TaskUpsertOne) SetParentUID(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetParentUID(v)
	})
}

// UpdateParentUID sets the "parent_uid" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateParentUID() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateParentUID()
	})
}

// ClearParentUID clears the value of the "parent_uid" field.
func (u *TaskUpsertOne) ClearParentUID() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearParentUID()
	})
}

// SetRecurrence sets the "recurrence" field.
func (u *TaskUpsertOne) SetRecurrence(v map[string]interface{}) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetRecurrence(v)
	})
}

// UpdateRecurrence sets the "recurrence" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateRecurrence() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateRecurrence()
	})
}

// ClearRecurrence clears the value of the "recurrence" field.
func (u *TaskUpsertOne) ClearRecurrence() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearRecurrence()
	})
}

// SetReminders sets the "reminders" field.
func (u *TaskUpsertOne) SetReminders(v []map[string]interface{}) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetReminders(v)
	})
}

// UpdateReminders sets the "reminders" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateReminders() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateReminders()
	})
}

// ClearReminders clears the value of the "reminders" field.
func (u *TaskUpsertOne) ClearReminders() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearReminders()
	})
}

// SetCategories sets the "categories" field.
func (u *TaskUpsertOne) SetCategories(v []string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetCategories(v)
	})
}

// UpdateCategories sets the "categories" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateCategories() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateCategories()
	})
}

// ClearCategories clears the value of the "categories" field.
func (u *TaskUpsertOne) ClearCategories() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearCategories()
	})
}

// SetRawIcs sets the "raw_ics" field.
func (u *TaskUpsertOne) SetRawIcs(v string) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetRawIcs(v)
	})
}

// UpdateRawIcs sets the "raw_ics" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateRawIcs() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateRawIcs()
	})
}

// ClearRawIcs clears the value of the "raw_ics" field.
func (u *TaskUpsertOne) ClearRawIcs() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.ClearRawIcs()
	})
}

// SetCreated sets the "created" field.
func (u *TaskUpsertOne) SetCreated(v time.Time) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetCreated(v)
	})
}

// UpdateCreated sets the "created" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateCreated() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateCreated()
	})
}

// SetUpdated sets the "updated" field.
func (u *TaskUpsertOne) SetUpdated(v time.Time) *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.SetUpdated(v)
	})
}

// UpdateUpdated sets the "updated" field to the value that was provided on create.
func (u *TaskUpsertOne) UpdateUpdated() *TaskUpsertOne {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateUpdated()
	})
}

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

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

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

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

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

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

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

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

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

// TaskUpsertBulk is the builder for "upsert"-ing
// a bulk of Task nodes.
type TaskUpsertBulk struct {
	create *TaskCreateBulk
}

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

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

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

// SetUID sets the "uid" field.
func (u *TaskUpsertBulk) SetUID(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetUID(v)
	})
}

// UpdateUID sets the "uid" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateUID() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateUID()
	})
}

// SetRemoteID sets the "remote_id" field.
func (u *TaskUpsertBulk) SetRemoteID(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetRemoteID(v)
	})
}

// UpdateRemoteID sets the "remote_id" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateRemoteID() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateRemoteID()
	})
}

// ClearRemoteID clears the value of the "remote_id" field.
func (u *TaskUpsertBulk) ClearRemoteID() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearRemoteID()
	})
}

// SetEtag sets the "etag" field.
func (u *TaskUpsertBulk) SetEtag(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetEtag(v)
	})
}

// UpdateEtag sets the "etag" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateEtag() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateEtag()
	})
}

// ClearEtag clears the value of the "etag" field.
func (u *TaskUpsertBulk) ClearEtag() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearEtag()
	})
}

// SetSummary sets the "summary" field.
func (u *TaskUpsertBulk) SetSummary(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetSummary(v)
	})
}

// UpdateSummary sets the "summary" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateSummary() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateSummary()
	})
}

// SetDescription sets the "description" field.
func (u *TaskUpsertBulk) SetDescription(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetDescription(v)
	})
}

// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateDescription() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateDescription()
	})
}

// ClearDescription clears the value of the "description" field.
func (u *TaskUpsertBulk) ClearDescription() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearDescription()
	})
}

// SetLocation sets the "location" field.
func (u *TaskUpsertBulk) SetLocation(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetLocation(v)
	})
}

// UpdateLocation sets the "location" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateLocation() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateLocation()
	})
}

// ClearLocation clears the value of the "location" field.
func (u *TaskUpsertBulk) ClearLocation() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearLocation()
	})
}

// SetStatus sets the "status" field.
func (u *TaskUpsertBulk) SetStatus(v task.Status) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetStatus(v)
	})
}

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

// SetPriority sets the "priority" field.
func (u *TaskUpsertBulk) SetPriority(v int) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetPriority(v)
	})
}

// AddPriority adds v to the "priority" field.
func (u *TaskUpsertBulk) AddPriority(v int) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.AddPriority(v)
	})
}

// UpdatePriority sets the "priority" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdatePriority() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdatePriority()
	})
}

// SetPercentComplete sets the "percent_complete" field.
func (u *TaskUpsertBulk) SetPercentComplete(v int) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetPercentComplete(v)
	})
}

// AddPercentComplete adds v to the "percent_complete" field.
func (u *TaskUpsertBulk) AddPercentComplete(v int) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.AddPercentComplete(v)
	})
}

// UpdatePercentComplete sets the "percent_complete" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdatePercentComplete() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdatePercentComplete()
	})
}

// SetDue sets the "due" field.
func (u *TaskUpsertBulk) SetDue(v time.Time) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetDue(v)
	})
}

// UpdateDue sets the "due" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateDue() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateDue()
	})
}

// ClearDue clears the value of the "due" field.
func (u *TaskUpsertBulk) ClearDue() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearDue()
	})
}

// SetStart sets the "start" field.
func (u *TaskUpsertBulk) SetStart(v time.Time) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetStart(v)
	})
}

// UpdateStart sets the "start" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateStart() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateStart()
	})
}

// ClearStart clears the value of the "start" field.
func (u *TaskUpsertBulk) ClearStart() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearStart()
	})
}

// SetCompleted sets the "completed" field.
func (u *TaskUpsertBulk) SetCompleted(v time.Time) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetCompleted(v)
	})
}

// UpdateCompleted sets the "completed" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateCompleted() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateCompleted()
	})
}

// ClearCompleted clears the value of the "completed" field.
func (u *TaskUpsertBulk) ClearCompleted() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearCompleted()
	})
}

// SetAllDay sets the "all_day" field.
func (u *TaskUpsertBulk) SetAllDay(v bool) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetAllDay(v)
	})
}

// UpdateAllDay sets the "all_day" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateAllDay() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateAllDay()
	})
}

// SetDueTz sets the "due_tz" field.
func (u *TaskUpsertBulk) SetDueTz(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetDueTz(v)
	})
}

// UpdateDueTz sets the "due_tz" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateDueTz() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateDueTz()
	})
}

// ClearDueTz clears the value of the "due_tz" field.
func (u *TaskUpsertBulk) ClearDueTz() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearDueTz()
	})
}

// SetStartTz sets the "start_tz" field.
func (u *TaskUpsertBulk) SetStartTz(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetStartTz(v)
	})
}

// UpdateStartTz sets the "start_tz" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateStartTz() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateStartTz()
	})
}

// ClearStartTz clears the value of the "start_tz" field.
func (u *TaskUpsertBulk) ClearStartTz() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearStartTz()
	})
}

// SetParentUID sets the "parent_uid" field.
func (u *TaskUpsertBulk) SetParentUID(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetParentUID(v)
	})
}

// UpdateParentUID sets the "parent_uid" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateParentUID() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateParentUID()
	})
}

// ClearParentUID clears the value of the "parent_uid" field.
func (u *TaskUpsertBulk) ClearParentUID() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearParentUID()
	})
}

// SetRecurrence sets the "recurrence" field.
func (u *TaskUpsertBulk) SetRecurrence(v map[string]interface{}) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetRecurrence(v)
	})
}

// UpdateRecurrence sets the "recurrence" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateRecurrence() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateRecurrence()
	})
}

// ClearRecurrence clears the value of the "recurrence" field.
func (u *TaskUpsertBulk) ClearRecurrence() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearRecurrence()
	})
}

// SetReminders sets the "reminders" field.
func (u *TaskUpsertBulk) SetReminders(v []map[string]interface{}) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetReminders(v)
	})
}

// UpdateReminders sets the "reminders" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateReminders() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateReminders()
	})
}

// ClearReminders clears the value of the "reminders" field.
func (u *TaskUpsertBulk) ClearReminders() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearReminders()
	})
}

// SetCategories sets the "categories" field.
func (u *TaskUpsertBulk) SetCategories(v []string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetCategories(v)
	})
}

// UpdateCategories sets the "categories" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateCategories() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateCategories()
	})
}

// ClearCategories clears the value of the "categories" field.
func (u *TaskUpsertBulk) ClearCategories() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearCategories()
	})
}

// SetRawIcs sets the "raw_ics" field.
func (u *TaskUpsertBulk) SetRawIcs(v string) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetRawIcs(v)
	})
}

// UpdateRawIcs sets the "raw_ics" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateRawIcs() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateRawIcs()
	})
}

// ClearRawIcs clears the value of the "raw_ics" field.
func (u *TaskUpsertBulk) ClearRawIcs() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.ClearRawIcs()
	})
}

// SetCreated sets the "created" field.
func (u *TaskUpsertBulk) SetCreated(v time.Time) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetCreated(v)
	})
}

// UpdateCreated sets the "created" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateCreated() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateCreated()
	})
}

// SetUpdated sets the "updated" field.
func (u *TaskUpsertBulk) SetUpdated(v time.Time) *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.SetUpdated(v)
	})
}

// UpdateUpdated sets the "updated" field to the value that was provided on create.
func (u *TaskUpsertBulk) UpdateUpdated() *TaskUpsertBulk {
	return u.Update(func(s *TaskUpsert) {
		s.UpdateUpdated()
	})
}

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

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