// 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/page"
)

// PageCreate is the builder for creating a Page entity.
type PageCreate struct {
	config
	mutation *PageMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetDeletedAt sets the "deleted_at" field.
func (_c *PageCreate) SetDeletedAt(v time.Time) *PageCreate {
	_c.mutation.SetDeletedAt(v)
	return _c
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_c *PageCreate) SetNillableDeletedAt(v *time.Time) *PageCreate {
	if v != nil {
		_c.SetDeletedAt(*v)
	}
	return _c
}

// SetTitle sets the "title" field.
func (_c *PageCreate) SetTitle(v string) *PageCreate {
	_c.mutation.SetTitle(v)
	return _c
}

// SetPath sets the "path" field.
func (_c *PageCreate) SetPath(v string) *PageCreate {
	_c.mutation.SetPath(v)
	return _c
}

// SetContent sets the "content" field.
func (_c *PageCreate) SetContent(v string) *PageCreate {
	_c.mutation.SetContent(v)
	return _c
}

// SetMarkdownContent sets the "markdown_content" field.
func (_c *PageCreate) SetMarkdownContent(v string) *PageCreate {
	_c.mutation.SetMarkdownContent(v)
	return _c
}

// SetNillableMarkdownContent sets the "markdown_content" field if the given value is not nil.
func (_c *PageCreate) SetNillableMarkdownContent(v *string) *PageCreate {
	if v != nil {
		_c.SetMarkdownContent(*v)
	}
	return _c
}

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

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

// SetIsPublished sets the "is_published" field.
func (_c *PageCreate) SetIsPublished(v bool) *PageCreate {
	_c.mutation.SetIsPublished(v)
	return _c
}

// SetNillableIsPublished sets the "is_published" field if the given value is not nil.
func (_c *PageCreate) SetNillableIsPublished(v *bool) *PageCreate {
	if v != nil {
		_c.SetIsPublished(*v)
	}
	return _c
}

// SetShowComment sets the "show_comment" field.
func (_c *PageCreate) SetShowComment(v bool) *PageCreate {
	_c.mutation.SetShowComment(v)
	return _c
}

// SetNillableShowComment sets the "show_comment" field if the given value is not nil.
func (_c *PageCreate) SetNillableShowComment(v *bool) *PageCreate {
	if v != nil {
		_c.SetShowComment(*v)
	}
	return _c
}

// SetSort sets the "sort" field.
func (_c *PageCreate) SetSort(v int) *PageCreate {
	_c.mutation.SetSort(v)
	return _c
}

// SetNillableSort sets the "sort" field if the given value is not nil.
func (_c *PageCreate) SetNillableSort(v *int) *PageCreate {
	if v != nil {
		_c.SetSort(*v)
	}
	return _c
}

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

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

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

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

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

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

// Save creates the Page in the database.
func (_c *PageCreate) Save(ctx context.Context) (*Page, error) {
	if err := _c.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *PageCreate) 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 *PageCreate) defaults() error {
	if _, ok := _c.mutation.MarkdownContent(); !ok {
		v := page.DefaultMarkdownContent
		_c.mutation.SetMarkdownContent(v)
	}
	if _, ok := _c.mutation.IsPublished(); !ok {
		v := page.DefaultIsPublished
		_c.mutation.SetIsPublished(v)
	}
	if _, ok := _c.mutation.ShowComment(); !ok {
		v := page.DefaultShowComment
		_c.mutation.SetShowComment(v)
	}
	if _, ok := _c.mutation.Sort(); !ok {
		v := page.DefaultSort
		_c.mutation.SetSort(v)
	}
	if _, ok := _c.mutation.CreatedAt(); !ok {
		if page.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized page.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := page.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		if page.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized page.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := page.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_c *PageCreate) check() error {
	if _, ok := _c.mutation.Title(); !ok {
		return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Page.title"`)}
	}
	if v, ok := _c.mutation.Title(); ok {
		if err := page.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Page.title": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Path(); !ok {
		return &ValidationError{Name: "path", err: errors.New(`ent: missing required field "Page.path"`)}
	}
	if v, ok := _c.mutation.Path(); ok {
		if err := page.PathValidator(v); err != nil {
			return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Page.path": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Content(); !ok {
		return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Page.content"`)}
	}
	if _, ok := _c.mutation.MarkdownContent(); !ok {
		return &ValidationError{Name: "markdown_content", err: errors.New(`ent: missing required field "Page.markdown_content"`)}
	}
	if v, ok := _c.mutation.Description(); ok {
		if err := page.DescriptionValidator(v); err != nil {
			return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Page.description": %w`, err)}
		}
	}
	if _, ok := _c.mutation.IsPublished(); !ok {
		return &ValidationError{Name: "is_published", err: errors.New(`ent: missing required field "Page.is_published"`)}
	}
	if _, ok := _c.mutation.ShowComment(); !ok {
		return &ValidationError{Name: "show_comment", err: errors.New(`ent: missing required field "Page.show_comment"`)}
	}
	if _, ok := _c.mutation.Sort(); !ok {
		return &ValidationError{Name: "sort", err: errors.New(`ent: missing required field "Page.sort"`)}
	}
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Page.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Page.updated_at"`)}
	}
	return nil
}

func (_c *PageCreate) sqlSave(ctx context.Context) (*Page, 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 *PageCreate) createSpec() (*Page, *sqlgraph.CreateSpec) {
	var (
		_node = &Page{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(page.Table, sqlgraph.NewFieldSpec(page.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.DeletedAt(); ok {
		_spec.SetField(page.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = &value
	}
	if value, ok := _c.mutation.Title(); ok {
		_spec.SetField(page.FieldTitle, field.TypeString, value)
		_node.Title = value
	}
	if value, ok := _c.mutation.Path(); ok {
		_spec.SetField(page.FieldPath, field.TypeString, value)
		_node.Path = value
	}
	if value, ok := _c.mutation.Content(); ok {
		_spec.SetField(page.FieldContent, field.TypeString, value)
		_node.Content = value
	}
	if value, ok := _c.mutation.MarkdownContent(); ok {
		_spec.SetField(page.FieldMarkdownContent, field.TypeString, value)
		_node.MarkdownContent = value
	}
	if value, ok := _c.mutation.Description(); ok {
		_spec.SetField(page.FieldDescription, field.TypeString, value)
		_node.Description = value
	}
	if value, ok := _c.mutation.IsPublished(); ok {
		_spec.SetField(page.FieldIsPublished, field.TypeBool, value)
		_node.IsPublished = value
	}
	if value, ok := _c.mutation.ShowComment(); ok {
		_spec.SetField(page.FieldShowComment, field.TypeBool, value)
		_node.ShowComment = value
	}
	if value, ok := _c.mutation.Sort(); ok {
		_spec.SetField(page.FieldSort, field.TypeInt, value)
		_node.Sort = value
	}
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(page.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(page.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	return _node, _spec
}

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

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

type (
	// PageUpsertOne is the builder for "upsert"-ing
	//  one Page node.
	PageUpsertOne struct {
		create *PageCreate
	}

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

// SetDeletedAt sets the "deleted_at" field.
func (u *PageUpsert) SetDeletedAt(v time.Time) *PageUpsert {
	u.Set(page.FieldDeletedAt, v)
	return u
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *PageUpsert) UpdateDeletedAt() *PageUpsert {
	u.SetExcluded(page.FieldDeletedAt)
	return u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *PageUpsert) ClearDeletedAt() *PageUpsert {
	u.SetNull(page.FieldDeletedAt)
	return u
}

// SetTitle sets the "title" field.
func (u *PageUpsert) SetTitle(v string) *PageUpsert {
	u.Set(page.FieldTitle, v)
	return u
}

// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *PageUpsert) UpdateTitle() *PageUpsert {
	u.SetExcluded(page.FieldTitle)
	return u
}

// SetPath sets the "path" field.
func (u *PageUpsert) SetPath(v string) *PageUpsert {
	u.Set(page.FieldPath, v)
	return u
}

// UpdatePath sets the "path" field to the value that was provided on create.
func (u *PageUpsert) UpdatePath() *PageUpsert {
	u.SetExcluded(page.FieldPath)
	return u
}

// SetContent sets the "content" field.
func (u *PageUpsert) SetContent(v string) *PageUpsert {
	u.Set(page.FieldContent, v)
	return u
}

// UpdateContent sets the "content" field to the value that was provided on create.
func (u *PageUpsert) UpdateContent() *PageUpsert {
	u.SetExcluded(page.FieldContent)
	return u
}

// SetMarkdownContent sets the "markdown_content" field.
func (u *PageUpsert) SetMarkdownContent(v string) *PageUpsert {
	u.Set(page.FieldMarkdownContent, v)
	return u
}

// UpdateMarkdownContent sets the "markdown_content" field to the value that was provided on create.
func (u *PageUpsert) UpdateMarkdownContent() *PageUpsert {
	u.SetExcluded(page.FieldMarkdownContent)
	return u
}

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

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

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

// SetIsPublished sets the "is_published" field.
func (u *PageUpsert) SetIsPublished(v bool) *PageUpsert {
	u.Set(page.FieldIsPublished, v)
	return u
}

// UpdateIsPublished sets the "is_published" field to the value that was provided on create.
func (u *PageUpsert) UpdateIsPublished() *PageUpsert {
	u.SetExcluded(page.FieldIsPublished)
	return u
}

// SetShowComment sets the "show_comment" field.
func (u *PageUpsert) SetShowComment(v bool) *PageUpsert {
	u.Set(page.FieldShowComment, v)
	return u
}

// UpdateShowComment sets the "show_comment" field to the value that was provided on create.
func (u *PageUpsert) UpdateShowComment() *PageUpsert {
	u.SetExcluded(page.FieldShowComment)
	return u
}

// SetSort sets the "sort" field.
func (u *PageUpsert) SetSort(v int) *PageUpsert {
	u.Set(page.FieldSort, v)
	return u
}

// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *PageUpsert) UpdateSort() *PageUpsert {
	u.SetExcluded(page.FieldSort)
	return u
}

// AddSort adds v to the "sort" field.
func (u *PageUpsert) AddSort(v int) *PageUpsert {
	u.Add(page.FieldSort, v)
	return u
}

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

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *PageUpsert) UpdateUpdatedAt() *PageUpsert {
	u.SetExcluded(page.FieldUpdatedAt)
	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.Page.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(page.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *PageUpsertOne) UpdateNewValues() *PageUpsertOne {
	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(page.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(page.FieldCreatedAt)
		}
	}))
	return u
}

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *PageUpsertOne) SetDeletedAt(v time.Time) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateDeletedAt() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *PageUpsertOne) ClearDeletedAt() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.ClearDeletedAt()
	})
}

// SetTitle sets the "title" field.
func (u *PageUpsertOne) SetTitle(v string) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetTitle(v)
	})
}

// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateTitle() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateTitle()
	})
}

// SetPath sets the "path" field.
func (u *PageUpsertOne) SetPath(v string) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetPath(v)
	})
}

// UpdatePath sets the "path" field to the value that was provided on create.
func (u *PageUpsertOne) UpdatePath() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdatePath()
	})
}

// SetContent sets the "content" field.
func (u *PageUpsertOne) SetContent(v string) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetContent(v)
	})
}

// UpdateContent sets the "content" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateContent() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateContent()
	})
}

// SetMarkdownContent sets the "markdown_content" field.
func (u *PageUpsertOne) SetMarkdownContent(v string) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetMarkdownContent(v)
	})
}

// UpdateMarkdownContent sets the "markdown_content" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateMarkdownContent() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateMarkdownContent()
	})
}

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

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

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

// SetIsPublished sets the "is_published" field.
func (u *PageUpsertOne) SetIsPublished(v bool) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetIsPublished(v)
	})
}

// UpdateIsPublished sets the "is_published" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateIsPublished() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateIsPublished()
	})
}

// SetShowComment sets the "show_comment" field.
func (u *PageUpsertOne) SetShowComment(v bool) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetShowComment(v)
	})
}

// UpdateShowComment sets the "show_comment" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateShowComment() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateShowComment()
	})
}

// SetSort sets the "sort" field.
func (u *PageUpsertOne) SetSort(v int) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.SetSort(v)
	})
}

// AddSort adds v to the "sort" field.
func (u *PageUpsertOne) AddSort(v int) *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.AddSort(v)
	})
}

// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *PageUpsertOne) UpdateSort() *PageUpsertOne {
	return u.Update(func(s *PageUpsert) {
		s.UpdateSort()
	})
}

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

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

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

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

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

// Save creates the Page entities in the database.
func (_c *PageCreateBulk) Save(ctx context.Context) ([]*Page, error) {
	if _c.err != nil {
		return nil, _c.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
	nodes := make([]*Page, 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.(*PageMutation)
				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 *PageCreateBulk) SaveX(ctx context.Context) []*Page {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

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

// PageUpsertBulk is the builder for "upsert"-ing
// a bulk of Page nodes.
type PageUpsertBulk struct {
	create *PageCreateBulk
}

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *PageUpsertBulk) SetDeletedAt(v time.Time) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateDeletedAt() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *PageUpsertBulk) ClearDeletedAt() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.ClearDeletedAt()
	})
}

// SetTitle sets the "title" field.
func (u *PageUpsertBulk) SetTitle(v string) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetTitle(v)
	})
}

// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateTitle() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateTitle()
	})
}

// SetPath sets the "path" field.
func (u *PageUpsertBulk) SetPath(v string) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetPath(v)
	})
}

// UpdatePath sets the "path" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdatePath() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdatePath()
	})
}

// SetContent sets the "content" field.
func (u *PageUpsertBulk) SetContent(v string) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetContent(v)
	})
}

// UpdateContent sets the "content" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateContent() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateContent()
	})
}

// SetMarkdownContent sets the "markdown_content" field.
func (u *PageUpsertBulk) SetMarkdownContent(v string) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetMarkdownContent(v)
	})
}

// UpdateMarkdownContent sets the "markdown_content" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateMarkdownContent() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateMarkdownContent()
	})
}

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

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

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

// SetIsPublished sets the "is_published" field.
func (u *PageUpsertBulk) SetIsPublished(v bool) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetIsPublished(v)
	})
}

// UpdateIsPublished sets the "is_published" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateIsPublished() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateIsPublished()
	})
}

// SetShowComment sets the "show_comment" field.
func (u *PageUpsertBulk) SetShowComment(v bool) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetShowComment(v)
	})
}

// UpdateShowComment sets the "show_comment" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateShowComment() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateShowComment()
	})
}

// SetSort sets the "sort" field.
func (u *PageUpsertBulk) SetSort(v int) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.SetSort(v)
	})
}

// AddSort adds v to the "sort" field.
func (u *PageUpsertBulk) AddSort(v int) *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.AddSort(v)
	})
}

// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *PageUpsertBulk) UpdateSort() *PageUpsertBulk {
	return u.Update(func(s *PageUpsert) {
		s.UpdateSort()
	})
}

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

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

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

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