// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/anzhiyu-c/anheyu-app/ent/visitorstat"
)

// VisitorStatCreate is the builder for creating a VisitorStat entity.
type VisitorStatCreate struct {
	config
	mutation *VisitorStatMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

// SetUpdatedAt sets the "updated_at" field.
func (_c *VisitorStatCreate) SetUpdatedAt(v time.Time) *VisitorStatCreate {
	_c.mutation.SetUpdatedAt(v)
	return _c
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *VisitorStatCreate) SetNillableUpdatedAt(v *time.Time) *VisitorStatCreate {
	if v != nil {
		_c.SetUpdatedAt(*v)
	}
	return _c
}

// SetDate sets the "date" field.
func (_c *VisitorStatCreate) SetDate(v time.Time) *VisitorStatCreate {
	_c.mutation.SetDate(v)
	return _c
}

// SetUniqueVisitors sets the "unique_visitors" field.
func (_c *VisitorStatCreate) SetUniqueVisitors(v int64) *VisitorStatCreate {
	_c.mutation.SetUniqueVisitors(v)
	return _c
}

// SetNillableUniqueVisitors sets the "unique_visitors" field if the given value is not nil.
func (_c *VisitorStatCreate) SetNillableUniqueVisitors(v *int64) *VisitorStatCreate {
	if v != nil {
		_c.SetUniqueVisitors(*v)
	}
	return _c
}

// SetTotalViews sets the "total_views" field.
func (_c *VisitorStatCreate) SetTotalViews(v int64) *VisitorStatCreate {
	_c.mutation.SetTotalViews(v)
	return _c
}

// SetNillableTotalViews sets the "total_views" field if the given value is not nil.
func (_c *VisitorStatCreate) SetNillableTotalViews(v *int64) *VisitorStatCreate {
	if v != nil {
		_c.SetTotalViews(*v)
	}
	return _c
}

// SetPageViews sets the "page_views" field.
func (_c *VisitorStatCreate) SetPageViews(v int64) *VisitorStatCreate {
	_c.mutation.SetPageViews(v)
	return _c
}

// SetNillablePageViews sets the "page_views" field if the given value is not nil.
func (_c *VisitorStatCreate) SetNillablePageViews(v *int64) *VisitorStatCreate {
	if v != nil {
		_c.SetPageViews(*v)
	}
	return _c
}

// SetBounceCount sets the "bounce_count" field.
func (_c *VisitorStatCreate) SetBounceCount(v int64) *VisitorStatCreate {
	_c.mutation.SetBounceCount(v)
	return _c
}

// SetNillableBounceCount sets the "bounce_count" field if the given value is not nil.
func (_c *VisitorStatCreate) SetNillableBounceCount(v *int64) *VisitorStatCreate {
	if v != nil {
		_c.SetBounceCount(*v)
	}
	return _c
}

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

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

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

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *VisitorStatCreate) 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 *VisitorStatCreate) defaults() {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		v := visitorstat.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		v := visitorstat.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
	if _, ok := _c.mutation.UniqueVisitors(); !ok {
		v := visitorstat.DefaultUniqueVisitors
		_c.mutation.SetUniqueVisitors(v)
	}
	if _, ok := _c.mutation.TotalViews(); !ok {
		v := visitorstat.DefaultTotalViews
		_c.mutation.SetTotalViews(v)
	}
	if _, ok := _c.mutation.PageViews(); !ok {
		v := visitorstat.DefaultPageViews
		_c.mutation.SetPageViews(v)
	}
	if _, ok := _c.mutation.BounceCount(); !ok {
		v := visitorstat.DefaultBounceCount
		_c.mutation.SetBounceCount(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_c *VisitorStatCreate) check() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "VisitorStat.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "VisitorStat.updated_at"`)}
	}
	if _, ok := _c.mutation.Date(); !ok {
		return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "VisitorStat.date"`)}
	}
	if _, ok := _c.mutation.UniqueVisitors(); !ok {
		return &ValidationError{Name: "unique_visitors", err: errors.New(`ent: missing required field "VisitorStat.unique_visitors"`)}
	}
	if _, ok := _c.mutation.TotalViews(); !ok {
		return &ValidationError{Name: "total_views", err: errors.New(`ent: missing required field "VisitorStat.total_views"`)}
	}
	if _, ok := _c.mutation.PageViews(); !ok {
		return &ValidationError{Name: "page_views", err: errors.New(`ent: missing required field "VisitorStat.page_views"`)}
	}
	if _, ok := _c.mutation.BounceCount(); !ok {
		return &ValidationError{Name: "bounce_count", err: errors.New(`ent: missing required field "VisitorStat.bounce_count"`)}
	}
	return nil
}

func (_c *VisitorStatCreate) sqlSave(ctx context.Context) (*VisitorStat, 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 != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = uint(id)
	}
	_c.mutation.id = &_node.ID
	_c.mutation.done = true
	return _node, nil
}

func (_c *VisitorStatCreate) createSpec() (*VisitorStat, *sqlgraph.CreateSpec) {
	var (
		_node = &VisitorStat{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(visitorstat.Table, sqlgraph.NewFieldSpec(visitorstat.FieldID, field.TypeUint))
	)
	_spec.OnConflict = _c.conflict
	if id, ok := _c.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(visitorstat.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(visitorstat.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := _c.mutation.Date(); ok {
		_spec.SetField(visitorstat.FieldDate, field.TypeTime, value)
		_node.Date = value
	}
	if value, ok := _c.mutation.UniqueVisitors(); ok {
		_spec.SetField(visitorstat.FieldUniqueVisitors, field.TypeInt64, value)
		_node.UniqueVisitors = value
	}
	if value, ok := _c.mutation.TotalViews(); ok {
		_spec.SetField(visitorstat.FieldTotalViews, field.TypeInt64, value)
		_node.TotalViews = value
	}
	if value, ok := _c.mutation.PageViews(); ok {
		_spec.SetField(visitorstat.FieldPageViews, field.TypeInt64, value)
		_node.PageViews = value
	}
	if value, ok := _c.mutation.BounceCount(); ok {
		_spec.SetField(visitorstat.FieldBounceCount, field.TypeInt64, value)
		_node.BounceCount = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.VisitorStat.Create().
//		SetCreatedAt(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.VisitorStatUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *VisitorStatCreate) OnConflict(opts ...sql.ConflictOption) *VisitorStatUpsertOne {
	_c.conflict = opts
	return &VisitorStatUpsertOne{
		create: _c,
	}
}

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

type (
	// VisitorStatUpsertOne is the builder for "upsert"-ing
	//  one VisitorStat node.
	VisitorStatUpsertOne struct {
		create *VisitorStatCreate
	}

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

// SetUpdatedAt sets the "updated_at" field.
func (u *VisitorStatUpsert) SetUpdatedAt(v time.Time) *VisitorStatUpsert {
	u.Set(visitorstat.FieldUpdatedAt, v)
	return u
}

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

// SetDate sets the "date" field.
func (u *VisitorStatUpsert) SetDate(v time.Time) *VisitorStatUpsert {
	u.Set(visitorstat.FieldDate, v)
	return u
}

// UpdateDate sets the "date" field to the value that was provided on create.
func (u *VisitorStatUpsert) UpdateDate() *VisitorStatUpsert {
	u.SetExcluded(visitorstat.FieldDate)
	return u
}

// SetUniqueVisitors sets the "unique_visitors" field.
func (u *VisitorStatUpsert) SetUniqueVisitors(v int64) *VisitorStatUpsert {
	u.Set(visitorstat.FieldUniqueVisitors, v)
	return u
}

// UpdateUniqueVisitors sets the "unique_visitors" field to the value that was provided on create.
func (u *VisitorStatUpsert) UpdateUniqueVisitors() *VisitorStatUpsert {
	u.SetExcluded(visitorstat.FieldUniqueVisitors)
	return u
}

// AddUniqueVisitors adds v to the "unique_visitors" field.
func (u *VisitorStatUpsert) AddUniqueVisitors(v int64) *VisitorStatUpsert {
	u.Add(visitorstat.FieldUniqueVisitors, v)
	return u
}

// SetTotalViews sets the "total_views" field.
func (u *VisitorStatUpsert) SetTotalViews(v int64) *VisitorStatUpsert {
	u.Set(visitorstat.FieldTotalViews, v)
	return u
}

// UpdateTotalViews sets the "total_views" field to the value that was provided on create.
func (u *VisitorStatUpsert) UpdateTotalViews() *VisitorStatUpsert {
	u.SetExcluded(visitorstat.FieldTotalViews)
	return u
}

// AddTotalViews adds v to the "total_views" field.
func (u *VisitorStatUpsert) AddTotalViews(v int64) *VisitorStatUpsert {
	u.Add(visitorstat.FieldTotalViews, v)
	return u
}

// SetPageViews sets the "page_views" field.
func (u *VisitorStatUpsert) SetPageViews(v int64) *VisitorStatUpsert {
	u.Set(visitorstat.FieldPageViews, v)
	return u
}

// UpdatePageViews sets the "page_views" field to the value that was provided on create.
func (u *VisitorStatUpsert) UpdatePageViews() *VisitorStatUpsert {
	u.SetExcluded(visitorstat.FieldPageViews)
	return u
}

// AddPageViews adds v to the "page_views" field.
func (u *VisitorStatUpsert) AddPageViews(v int64) *VisitorStatUpsert {
	u.Add(visitorstat.FieldPageViews, v)
	return u
}

// SetBounceCount sets the "bounce_count" field.
func (u *VisitorStatUpsert) SetBounceCount(v int64) *VisitorStatUpsert {
	u.Set(visitorstat.FieldBounceCount, v)
	return u
}

// UpdateBounceCount sets the "bounce_count" field to the value that was provided on create.
func (u *VisitorStatUpsert) UpdateBounceCount() *VisitorStatUpsert {
	u.SetExcluded(visitorstat.FieldBounceCount)
	return u
}

// AddBounceCount adds v to the "bounce_count" field.
func (u *VisitorStatUpsert) AddBounceCount(v int64) *VisitorStatUpsert {
	u.Add(visitorstat.FieldBounceCount, v)
	return u
}

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

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

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

// SetUpdatedAt sets the "updated_at" field.
func (u *VisitorStatUpsertOne) SetUpdatedAt(v time.Time) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetUpdatedAt(v)
	})
}

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

// SetDate sets the "date" field.
func (u *VisitorStatUpsertOne) SetDate(v time.Time) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetDate(v)
	})
}

// UpdateDate sets the "date" field to the value that was provided on create.
func (u *VisitorStatUpsertOne) UpdateDate() *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateDate()
	})
}

// SetUniqueVisitors sets the "unique_visitors" field.
func (u *VisitorStatUpsertOne) SetUniqueVisitors(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetUniqueVisitors(v)
	})
}

// AddUniqueVisitors adds v to the "unique_visitors" field.
func (u *VisitorStatUpsertOne) AddUniqueVisitors(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddUniqueVisitors(v)
	})
}

// UpdateUniqueVisitors sets the "unique_visitors" field to the value that was provided on create.
func (u *VisitorStatUpsertOne) UpdateUniqueVisitors() *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateUniqueVisitors()
	})
}

// SetTotalViews sets the "total_views" field.
func (u *VisitorStatUpsertOne) SetTotalViews(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetTotalViews(v)
	})
}

// AddTotalViews adds v to the "total_views" field.
func (u *VisitorStatUpsertOne) AddTotalViews(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddTotalViews(v)
	})
}

// UpdateTotalViews sets the "total_views" field to the value that was provided on create.
func (u *VisitorStatUpsertOne) UpdateTotalViews() *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateTotalViews()
	})
}

// SetPageViews sets the "page_views" field.
func (u *VisitorStatUpsertOne) SetPageViews(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetPageViews(v)
	})
}

// AddPageViews adds v to the "page_views" field.
func (u *VisitorStatUpsertOne) AddPageViews(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddPageViews(v)
	})
}

// UpdatePageViews sets the "page_views" field to the value that was provided on create.
func (u *VisitorStatUpsertOne) UpdatePageViews() *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdatePageViews()
	})
}

// SetBounceCount sets the "bounce_count" field.
func (u *VisitorStatUpsertOne) SetBounceCount(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetBounceCount(v)
	})
}

// AddBounceCount adds v to the "bounce_count" field.
func (u *VisitorStatUpsertOne) AddBounceCount(v int64) *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddBounceCount(v)
	})
}

// UpdateBounceCount sets the "bounce_count" field to the value that was provided on create.
func (u *VisitorStatUpsertOne) UpdateBounceCount() *VisitorStatUpsertOne {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateBounceCount()
	})
}

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

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

// IDX is like ID, but panics if an error occurs.
func (u *VisitorStatUpsertOne) IDX(ctx context.Context) uint {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

// Save creates the VisitorStat entities in the database.
func (_c *VisitorStatCreateBulk) Save(ctx context.Context) ([]*VisitorStat, error) {
	if _c.err != nil {
		return nil, _c.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
	nodes := make([]*VisitorStat, 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.(*VisitorStatMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = _c.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = uint(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 *VisitorStatCreateBulk) SaveX(ctx context.Context) []*VisitorStat {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

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

// VisitorStatUpsertBulk is the builder for "upsert"-ing
// a bulk of VisitorStat nodes.
type VisitorStatUpsertBulk struct {
	create *VisitorStatCreateBulk
}

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

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

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

// SetUpdatedAt sets the "updated_at" field.
func (u *VisitorStatUpsertBulk) SetUpdatedAt(v time.Time) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetUpdatedAt(v)
	})
}

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

// SetDate sets the "date" field.
func (u *VisitorStatUpsertBulk) SetDate(v time.Time) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetDate(v)
	})
}

// UpdateDate sets the "date" field to the value that was provided on create.
func (u *VisitorStatUpsertBulk) UpdateDate() *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateDate()
	})
}

// SetUniqueVisitors sets the "unique_visitors" field.
func (u *VisitorStatUpsertBulk) SetUniqueVisitors(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetUniqueVisitors(v)
	})
}

// AddUniqueVisitors adds v to the "unique_visitors" field.
func (u *VisitorStatUpsertBulk) AddUniqueVisitors(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddUniqueVisitors(v)
	})
}

// UpdateUniqueVisitors sets the "unique_visitors" field to the value that was provided on create.
func (u *VisitorStatUpsertBulk) UpdateUniqueVisitors() *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateUniqueVisitors()
	})
}

// SetTotalViews sets the "total_views" field.
func (u *VisitorStatUpsertBulk) SetTotalViews(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetTotalViews(v)
	})
}

// AddTotalViews adds v to the "total_views" field.
func (u *VisitorStatUpsertBulk) AddTotalViews(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddTotalViews(v)
	})
}

// UpdateTotalViews sets the "total_views" field to the value that was provided on create.
func (u *VisitorStatUpsertBulk) UpdateTotalViews() *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateTotalViews()
	})
}

// SetPageViews sets the "page_views" field.
func (u *VisitorStatUpsertBulk) SetPageViews(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetPageViews(v)
	})
}

// AddPageViews adds v to the "page_views" field.
func (u *VisitorStatUpsertBulk) AddPageViews(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddPageViews(v)
	})
}

// UpdatePageViews sets the "page_views" field to the value that was provided on create.
func (u *VisitorStatUpsertBulk) UpdatePageViews() *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdatePageViews()
	})
}

// SetBounceCount sets the "bounce_count" field.
func (u *VisitorStatUpsertBulk) SetBounceCount(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.SetBounceCount(v)
	})
}

// AddBounceCount adds v to the "bounce_count" field.
func (u *VisitorStatUpsertBulk) AddBounceCount(v int64) *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.AddBounceCount(v)
	})
}

// UpdateBounceCount sets the "bounce_count" field to the value that was provided on create.
func (u *VisitorStatUpsertBulk) UpdateBounceCount() *VisitorStatUpsertBulk {
	return u.Update(func(s *VisitorStatUpsert) {
		s.UpdateBounceCount()
	})
}

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

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