// 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/comment"
	"github.com/anzhiyu-c/anheyu-app/ent/user"
)

// CommentCreate is the builder for creating a Comment entity.
type CommentCreate struct {
	config
	mutation *CommentMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

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

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

// SetTargetPath sets the "target_path" field.
func (_c *CommentCreate) SetTargetPath(v string) *CommentCreate {
	_c.mutation.SetTargetPath(v)
	return _c
}

// SetTargetTitle sets the "target_title" field.
func (_c *CommentCreate) SetTargetTitle(v string) *CommentCreate {
	_c.mutation.SetTargetTitle(v)
	return _c
}

// SetNillableTargetTitle sets the "target_title" field if the given value is not nil.
func (_c *CommentCreate) SetNillableTargetTitle(v *string) *CommentCreate {
	if v != nil {
		_c.SetTargetTitle(*v)
	}
	return _c
}

// SetUserID sets the "user_id" field.
func (_c *CommentCreate) SetUserID(v uint) *CommentCreate {
	_c.mutation.SetUserID(v)
	return _c
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_c *CommentCreate) SetNillableUserID(v *uint) *CommentCreate {
	if v != nil {
		_c.SetUserID(*v)
	}
	return _c
}

// SetParentID sets the "parent_id" field.
func (_c *CommentCreate) SetParentID(v uint) *CommentCreate {
	_c.mutation.SetParentID(v)
	return _c
}

// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (_c *CommentCreate) SetNillableParentID(v *uint) *CommentCreate {
	if v != nil {
		_c.SetParentID(*v)
	}
	return _c
}

// SetNickname sets the "nickname" field.
func (_c *CommentCreate) SetNickname(v string) *CommentCreate {
	_c.mutation.SetNickname(v)
	return _c
}

// SetEmail sets the "email" field.
func (_c *CommentCreate) SetEmail(v string) *CommentCreate {
	_c.mutation.SetEmail(v)
	return _c
}

// SetNillableEmail sets the "email" field if the given value is not nil.
func (_c *CommentCreate) SetNillableEmail(v *string) *CommentCreate {
	if v != nil {
		_c.SetEmail(*v)
	}
	return _c
}

// SetEmailMd5 sets the "email_md5" field.
func (_c *CommentCreate) SetEmailMd5(v string) *CommentCreate {
	_c.mutation.SetEmailMd5(v)
	return _c
}

// SetWebsite sets the "website" field.
func (_c *CommentCreate) SetWebsite(v string) *CommentCreate {
	_c.mutation.SetWebsite(v)
	return _c
}

// SetNillableWebsite sets the "website" field if the given value is not nil.
func (_c *CommentCreate) SetNillableWebsite(v *string) *CommentCreate {
	if v != nil {
		_c.SetWebsite(*v)
	}
	return _c
}

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

// SetContentHTML sets the "content_html" field.
func (_c *CommentCreate) SetContentHTML(v string) *CommentCreate {
	_c.mutation.SetContentHTML(v)
	return _c
}

// SetStatus sets the "status" field.
func (_c *CommentCreate) SetStatus(v int) *CommentCreate {
	_c.mutation.SetStatus(v)
	return _c
}

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

// SetIsAdminComment sets the "is_admin_comment" field.
func (_c *CommentCreate) SetIsAdminComment(v bool) *CommentCreate {
	_c.mutation.SetIsAdminComment(v)
	return _c
}

// SetNillableIsAdminComment sets the "is_admin_comment" field if the given value is not nil.
func (_c *CommentCreate) SetNillableIsAdminComment(v *bool) *CommentCreate {
	if v != nil {
		_c.SetIsAdminComment(*v)
	}
	return _c
}

// SetIsAnonymous sets the "is_anonymous" field.
func (_c *CommentCreate) SetIsAnonymous(v bool) *CommentCreate {
	_c.mutation.SetIsAnonymous(v)
	return _c
}

// SetNillableIsAnonymous sets the "is_anonymous" field if the given value is not nil.
func (_c *CommentCreate) SetNillableIsAnonymous(v *bool) *CommentCreate {
	if v != nil {
		_c.SetIsAnonymous(*v)
	}
	return _c
}

// SetAllowNotification sets the "allow_notification" field.
func (_c *CommentCreate) SetAllowNotification(v bool) *CommentCreate {
	_c.mutation.SetAllowNotification(v)
	return _c
}

// SetNillableAllowNotification sets the "allow_notification" field if the given value is not nil.
func (_c *CommentCreate) SetNillableAllowNotification(v *bool) *CommentCreate {
	if v != nil {
		_c.SetAllowNotification(*v)
	}
	return _c
}

// SetUserAgent sets the "user_agent" field.
func (_c *CommentCreate) SetUserAgent(v string) *CommentCreate {
	_c.mutation.SetUserAgent(v)
	return _c
}

// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
func (_c *CommentCreate) SetNillableUserAgent(v *string) *CommentCreate {
	if v != nil {
		_c.SetUserAgent(*v)
	}
	return _c
}

// SetIPAddress sets the "ip_address" field.
func (_c *CommentCreate) SetIPAddress(v string) *CommentCreate {
	_c.mutation.SetIPAddress(v)
	return _c
}

// SetIPLocation sets the "ip_location" field.
func (_c *CommentCreate) SetIPLocation(v string) *CommentCreate {
	_c.mutation.SetIPLocation(v)
	return _c
}

// SetNillableIPLocation sets the "ip_location" field if the given value is not nil.
func (_c *CommentCreate) SetNillableIPLocation(v *string) *CommentCreate {
	if v != nil {
		_c.SetIPLocation(*v)
	}
	return _c
}

// SetLikeCount sets the "like_count" field.
func (_c *CommentCreate) SetLikeCount(v int) *CommentCreate {
	_c.mutation.SetLikeCount(v)
	return _c
}

// SetNillableLikeCount sets the "like_count" field if the given value is not nil.
func (_c *CommentCreate) SetNillableLikeCount(v *int) *CommentCreate {
	if v != nil {
		_c.SetLikeCount(*v)
	}
	return _c
}

// SetPinnedAt sets the "pinned_at" field.
func (_c *CommentCreate) SetPinnedAt(v time.Time) *CommentCreate {
	_c.mutation.SetPinnedAt(v)
	return _c
}

// SetNillablePinnedAt sets the "pinned_at" field if the given value is not nil.
func (_c *CommentCreate) SetNillablePinnedAt(v *time.Time) *CommentCreate {
	if v != nil {
		_c.SetPinnedAt(*v)
	}
	return _c
}

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

// SetUser sets the "user" edge to the User entity.
func (_c *CommentCreate) SetUser(v *User) *CommentCreate {
	return _c.SetUserID(v.ID)
}

// SetChildrenID sets the "children" edge to the Comment entity by ID.
func (_c *CommentCreate) SetChildrenID(id uint) *CommentCreate {
	_c.mutation.SetChildrenID(id)
	return _c
}

// SetNillableChildrenID sets the "children" edge to the Comment entity by ID if the given value is not nil.
func (_c *CommentCreate) SetNillableChildrenID(id *uint) *CommentCreate {
	if id != nil {
		_c = _c.SetChildrenID(*id)
	}
	return _c
}

// SetChildren sets the "children" edge to the Comment entity.
func (_c *CommentCreate) SetChildren(v *Comment) *CommentCreate {
	return _c.SetChildrenID(v.ID)
}

// AddParentIDs adds the "parent" edge to the Comment entity by IDs.
func (_c *CommentCreate) AddParentIDs(ids ...uint) *CommentCreate {
	_c.mutation.AddParentIDs(ids...)
	return _c
}

// AddParent adds the "parent" edges to the Comment entity.
func (_c *CommentCreate) AddParent(v ...*Comment) *CommentCreate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddParentIDs(ids...)
}

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

// Save creates the Comment in the database.
func (_c *CommentCreate) Save(ctx context.Context) (*Comment, 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 *CommentCreate) SaveX(ctx context.Context) *Comment {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *CommentCreate) 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 *CommentCreate) defaults() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		if comment.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized comment.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := comment.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		if comment.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized comment.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := comment.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
	if _, ok := _c.mutation.Status(); !ok {
		v := comment.DefaultStatus
		_c.mutation.SetStatus(v)
	}
	if _, ok := _c.mutation.IsAdminComment(); !ok {
		v := comment.DefaultIsAdminComment
		_c.mutation.SetIsAdminComment(v)
	}
	if _, ok := _c.mutation.IsAnonymous(); !ok {
		v := comment.DefaultIsAnonymous
		_c.mutation.SetIsAnonymous(v)
	}
	if _, ok := _c.mutation.AllowNotification(); !ok {
		v := comment.DefaultAllowNotification
		_c.mutation.SetAllowNotification(v)
	}
	if _, ok := _c.mutation.LikeCount(); !ok {
		v := comment.DefaultLikeCount
		_c.mutation.SetLikeCount(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_c *CommentCreate) check() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Comment.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Comment.updated_at"`)}
	}
	if _, ok := _c.mutation.TargetPath(); !ok {
		return &ValidationError{Name: "target_path", err: errors.New(`ent: missing required field "Comment.target_path"`)}
	}
	if v, ok := _c.mutation.TargetPath(); ok {
		if err := comment.TargetPathValidator(v); err != nil {
			return &ValidationError{Name: "target_path", err: fmt.Errorf(`ent: validator failed for field "Comment.target_path": %w`, err)}
		}
	}
	if v, ok := _c.mutation.TargetTitle(); ok {
		if err := comment.TargetTitleValidator(v); err != nil {
			return &ValidationError{Name: "target_title", err: fmt.Errorf(`ent: validator failed for field "Comment.target_title": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Nickname(); !ok {
		return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "Comment.nickname"`)}
	}
	if v, ok := _c.mutation.Nickname(); ok {
		if err := comment.NicknameValidator(v); err != nil {
			return &ValidationError{Name: "nickname", err: fmt.Errorf(`ent: validator failed for field "Comment.nickname": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Email(); ok {
		if err := comment.EmailValidator(v); err != nil {
			return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "Comment.email": %w`, err)}
		}
	}
	if _, ok := _c.mutation.EmailMd5(); !ok {
		return &ValidationError{Name: "email_md5", err: errors.New(`ent: missing required field "Comment.email_md5"`)}
	}
	if v, ok := _c.mutation.EmailMd5(); ok {
		if err := comment.EmailMd5Validator(v); err != nil {
			return &ValidationError{Name: "email_md5", err: fmt.Errorf(`ent: validator failed for field "Comment.email_md5": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Website(); ok {
		if err := comment.WebsiteValidator(v); err != nil {
			return &ValidationError{Name: "website", err: fmt.Errorf(`ent: validator failed for field "Comment.website": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Content(); !ok {
		return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Comment.content"`)}
	}
	if v, ok := _c.mutation.Content(); ok {
		if err := comment.ContentValidator(v); err != nil {
			return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Comment.content": %w`, err)}
		}
	}
	if _, ok := _c.mutation.ContentHTML(); !ok {
		return &ValidationError{Name: "content_html", err: errors.New(`ent: missing required field "Comment.content_html"`)}
	}
	if v, ok := _c.mutation.ContentHTML(); ok {
		if err := comment.ContentHTMLValidator(v); err != nil {
			return &ValidationError{Name: "content_html", err: fmt.Errorf(`ent: validator failed for field "Comment.content_html": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Status(); !ok {
		return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Comment.status"`)}
	}
	if _, ok := _c.mutation.IsAdminComment(); !ok {
		return &ValidationError{Name: "is_admin_comment", err: errors.New(`ent: missing required field "Comment.is_admin_comment"`)}
	}
	if _, ok := _c.mutation.IsAnonymous(); !ok {
		return &ValidationError{Name: "is_anonymous", err: errors.New(`ent: missing required field "Comment.is_anonymous"`)}
	}
	if _, ok := _c.mutation.AllowNotification(); !ok {
		return &ValidationError{Name: "allow_notification", err: errors.New(`ent: missing required field "Comment.allow_notification"`)}
	}
	if v, ok := _c.mutation.UserAgent(); ok {
		if err := comment.UserAgentValidator(v); err != nil {
			return &ValidationError{Name: "user_agent", err: fmt.Errorf(`ent: validator failed for field "Comment.user_agent": %w`, err)}
		}
	}
	if _, ok := _c.mutation.IPAddress(); !ok {
		return &ValidationError{Name: "ip_address", err: errors.New(`ent: missing required field "Comment.ip_address"`)}
	}
	if v, ok := _c.mutation.IPAddress(); ok {
		if err := comment.IPAddressValidator(v); err != nil {
			return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "Comment.ip_address": %w`, err)}
		}
	}
	if v, ok := _c.mutation.IPLocation(); ok {
		if err := comment.IPLocationValidator(v); err != nil {
			return &ValidationError{Name: "ip_location", err: fmt.Errorf(`ent: validator failed for field "Comment.ip_location": %w`, err)}
		}
	}
	if _, ok := _c.mutation.LikeCount(); !ok {
		return &ValidationError{Name: "like_count", err: errors.New(`ent: missing required field "Comment.like_count"`)}
	}
	if v, ok := _c.mutation.LikeCount(); ok {
		if err := comment.LikeCountValidator(v); err != nil {
			return &ValidationError{Name: "like_count", err: fmt.Errorf(`ent: validator failed for field "Comment.like_count": %w`, err)}
		}
	}
	return nil
}

func (_c *CommentCreate) sqlSave(ctx context.Context) (*Comment, 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 *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) {
	var (
		_node = &Comment{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(comment.Table, sqlgraph.NewFieldSpec(comment.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(comment.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = &value
	}
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(comment.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(comment.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := _c.mutation.TargetPath(); ok {
		_spec.SetField(comment.FieldTargetPath, field.TypeString, value)
		_node.TargetPath = value
	}
	if value, ok := _c.mutation.TargetTitle(); ok {
		_spec.SetField(comment.FieldTargetTitle, field.TypeString, value)
		_node.TargetTitle = &value
	}
	if value, ok := _c.mutation.Nickname(); ok {
		_spec.SetField(comment.FieldNickname, field.TypeString, value)
		_node.Nickname = value
	}
	if value, ok := _c.mutation.Email(); ok {
		_spec.SetField(comment.FieldEmail, field.TypeString, value)
		_node.Email = &value
	}
	if value, ok := _c.mutation.EmailMd5(); ok {
		_spec.SetField(comment.FieldEmailMd5, field.TypeString, value)
		_node.EmailMd5 = value
	}
	if value, ok := _c.mutation.Website(); ok {
		_spec.SetField(comment.FieldWebsite, field.TypeString, value)
		_node.Website = &value
	}
	if value, ok := _c.mutation.Content(); ok {
		_spec.SetField(comment.FieldContent, field.TypeString, value)
		_node.Content = value
	}
	if value, ok := _c.mutation.ContentHTML(); ok {
		_spec.SetField(comment.FieldContentHTML, field.TypeString, value)
		_node.ContentHTML = value
	}
	if value, ok := _c.mutation.Status(); ok {
		_spec.SetField(comment.FieldStatus, field.TypeInt, value)
		_node.Status = value
	}
	if value, ok := _c.mutation.IsAdminComment(); ok {
		_spec.SetField(comment.FieldIsAdminComment, field.TypeBool, value)
		_node.IsAdminComment = value
	}
	if value, ok := _c.mutation.IsAnonymous(); ok {
		_spec.SetField(comment.FieldIsAnonymous, field.TypeBool, value)
		_node.IsAnonymous = value
	}
	if value, ok := _c.mutation.AllowNotification(); ok {
		_spec.SetField(comment.FieldAllowNotification, field.TypeBool, value)
		_node.AllowNotification = value
	}
	if value, ok := _c.mutation.UserAgent(); ok {
		_spec.SetField(comment.FieldUserAgent, field.TypeString, value)
		_node.UserAgent = &value
	}
	if value, ok := _c.mutation.IPAddress(); ok {
		_spec.SetField(comment.FieldIPAddress, field.TypeString, value)
		_node.IPAddress = value
	}
	if value, ok := _c.mutation.IPLocation(); ok {
		_spec.SetField(comment.FieldIPLocation, field.TypeString, value)
		_node.IPLocation = &value
	}
	if value, ok := _c.mutation.LikeCount(); ok {
		_spec.SetField(comment.FieldLikeCount, field.TypeInt, value)
		_node.LikeCount = value
	}
	if value, ok := _c.mutation.PinnedAt(); ok {
		_spec.SetField(comment.FieldPinnedAt, field.TypeTime, value)
		_node.PinnedAt = &value
	}
	if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   comment.UserTable,
			Columns: []string{comment.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.UserID = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   comment.ChildrenTable,
			Columns: []string{comment.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.ParentID = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   comment.ParentTable,
			Columns: []string{comment.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

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

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

type (
	// CommentUpsertOne is the builder for "upsert"-ing
	//  one Comment node.
	CommentUpsertOne struct {
		create *CommentCreate
	}

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

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

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

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

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

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

// SetTargetPath sets the "target_path" field.
func (u *CommentUpsert) SetTargetPath(v string) *CommentUpsert {
	u.Set(comment.FieldTargetPath, v)
	return u
}

// UpdateTargetPath sets the "target_path" field to the value that was provided on create.
func (u *CommentUpsert) UpdateTargetPath() *CommentUpsert {
	u.SetExcluded(comment.FieldTargetPath)
	return u
}

// SetTargetTitle sets the "target_title" field.
func (u *CommentUpsert) SetTargetTitle(v string) *CommentUpsert {
	u.Set(comment.FieldTargetTitle, v)
	return u
}

// UpdateTargetTitle sets the "target_title" field to the value that was provided on create.
func (u *CommentUpsert) UpdateTargetTitle() *CommentUpsert {
	u.SetExcluded(comment.FieldTargetTitle)
	return u
}

// ClearTargetTitle clears the value of the "target_title" field.
func (u *CommentUpsert) ClearTargetTitle() *CommentUpsert {
	u.SetNull(comment.FieldTargetTitle)
	return u
}

// SetUserID sets the "user_id" field.
func (u *CommentUpsert) SetUserID(v uint) *CommentUpsert {
	u.Set(comment.FieldUserID, v)
	return u
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CommentUpsert) UpdateUserID() *CommentUpsert {
	u.SetExcluded(comment.FieldUserID)
	return u
}

// ClearUserID clears the value of the "user_id" field.
func (u *CommentUpsert) ClearUserID() *CommentUpsert {
	u.SetNull(comment.FieldUserID)
	return u
}

// SetParentID sets the "parent_id" field.
func (u *CommentUpsert) SetParentID(v uint) *CommentUpsert {
	u.Set(comment.FieldParentID, v)
	return u
}

// UpdateParentID sets the "parent_id" field to the value that was provided on create.
func (u *CommentUpsert) UpdateParentID() *CommentUpsert {
	u.SetExcluded(comment.FieldParentID)
	return u
}

// ClearParentID clears the value of the "parent_id" field.
func (u *CommentUpsert) ClearParentID() *CommentUpsert {
	u.SetNull(comment.FieldParentID)
	return u
}

// SetNickname sets the "nickname" field.
func (u *CommentUpsert) SetNickname(v string) *CommentUpsert {
	u.Set(comment.FieldNickname, v)
	return u
}

// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *CommentUpsert) UpdateNickname() *CommentUpsert {
	u.SetExcluded(comment.FieldNickname)
	return u
}

// SetEmail sets the "email" field.
func (u *CommentUpsert) SetEmail(v string) *CommentUpsert {
	u.Set(comment.FieldEmail, v)
	return u
}

// UpdateEmail sets the "email" field to the value that was provided on create.
func (u *CommentUpsert) UpdateEmail() *CommentUpsert {
	u.SetExcluded(comment.FieldEmail)
	return u
}

// ClearEmail clears the value of the "email" field.
func (u *CommentUpsert) ClearEmail() *CommentUpsert {
	u.SetNull(comment.FieldEmail)
	return u
}

// SetEmailMd5 sets the "email_md5" field.
func (u *CommentUpsert) SetEmailMd5(v string) *CommentUpsert {
	u.Set(comment.FieldEmailMd5, v)
	return u
}

// UpdateEmailMd5 sets the "email_md5" field to the value that was provided on create.
func (u *CommentUpsert) UpdateEmailMd5() *CommentUpsert {
	u.SetExcluded(comment.FieldEmailMd5)
	return u
}

// SetWebsite sets the "website" field.
func (u *CommentUpsert) SetWebsite(v string) *CommentUpsert {
	u.Set(comment.FieldWebsite, v)
	return u
}

// UpdateWebsite sets the "website" field to the value that was provided on create.
func (u *CommentUpsert) UpdateWebsite() *CommentUpsert {
	u.SetExcluded(comment.FieldWebsite)
	return u
}

// ClearWebsite clears the value of the "website" field.
func (u *CommentUpsert) ClearWebsite() *CommentUpsert {
	u.SetNull(comment.FieldWebsite)
	return u
}

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

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

// SetContentHTML sets the "content_html" field.
func (u *CommentUpsert) SetContentHTML(v string) *CommentUpsert {
	u.Set(comment.FieldContentHTML, v)
	return u
}

// UpdateContentHTML sets the "content_html" field to the value that was provided on create.
func (u *CommentUpsert) UpdateContentHTML() *CommentUpsert {
	u.SetExcluded(comment.FieldContentHTML)
	return u
}

// SetStatus sets the "status" field.
func (u *CommentUpsert) SetStatus(v int) *CommentUpsert {
	u.Set(comment.FieldStatus, v)
	return u
}

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

// AddStatus adds v to the "status" field.
func (u *CommentUpsert) AddStatus(v int) *CommentUpsert {
	u.Add(comment.FieldStatus, v)
	return u
}

// SetIsAdminComment sets the "is_admin_comment" field.
func (u *CommentUpsert) SetIsAdminComment(v bool) *CommentUpsert {
	u.Set(comment.FieldIsAdminComment, v)
	return u
}

// UpdateIsAdminComment sets the "is_admin_comment" field to the value that was provided on create.
func (u *CommentUpsert) UpdateIsAdminComment() *CommentUpsert {
	u.SetExcluded(comment.FieldIsAdminComment)
	return u
}

// SetIsAnonymous sets the "is_anonymous" field.
func (u *CommentUpsert) SetIsAnonymous(v bool) *CommentUpsert {
	u.Set(comment.FieldIsAnonymous, v)
	return u
}

// UpdateIsAnonymous sets the "is_anonymous" field to the value that was provided on create.
func (u *CommentUpsert) UpdateIsAnonymous() *CommentUpsert {
	u.SetExcluded(comment.FieldIsAnonymous)
	return u
}

// SetAllowNotification sets the "allow_notification" field.
func (u *CommentUpsert) SetAllowNotification(v bool) *CommentUpsert {
	u.Set(comment.FieldAllowNotification, v)
	return u
}

// UpdateAllowNotification sets the "allow_notification" field to the value that was provided on create.
func (u *CommentUpsert) UpdateAllowNotification() *CommentUpsert {
	u.SetExcluded(comment.FieldAllowNotification)
	return u
}

// SetUserAgent sets the "user_agent" field.
func (u *CommentUpsert) SetUserAgent(v string) *CommentUpsert {
	u.Set(comment.FieldUserAgent, v)
	return u
}

// UpdateUserAgent sets the "user_agent" field to the value that was provided on create.
func (u *CommentUpsert) UpdateUserAgent() *CommentUpsert {
	u.SetExcluded(comment.FieldUserAgent)
	return u
}

// ClearUserAgent clears the value of the "user_agent" field.
func (u *CommentUpsert) ClearUserAgent() *CommentUpsert {
	u.SetNull(comment.FieldUserAgent)
	return u
}

// SetIPAddress sets the "ip_address" field.
func (u *CommentUpsert) SetIPAddress(v string) *CommentUpsert {
	u.Set(comment.FieldIPAddress, v)
	return u
}

// UpdateIPAddress sets the "ip_address" field to the value that was provided on create.
func (u *CommentUpsert) UpdateIPAddress() *CommentUpsert {
	u.SetExcluded(comment.FieldIPAddress)
	return u
}

// SetIPLocation sets the "ip_location" field.
func (u *CommentUpsert) SetIPLocation(v string) *CommentUpsert {
	u.Set(comment.FieldIPLocation, v)
	return u
}

// UpdateIPLocation sets the "ip_location" field to the value that was provided on create.
func (u *CommentUpsert) UpdateIPLocation() *CommentUpsert {
	u.SetExcluded(comment.FieldIPLocation)
	return u
}

// ClearIPLocation clears the value of the "ip_location" field.
func (u *CommentUpsert) ClearIPLocation() *CommentUpsert {
	u.SetNull(comment.FieldIPLocation)
	return u
}

// SetLikeCount sets the "like_count" field.
func (u *CommentUpsert) SetLikeCount(v int) *CommentUpsert {
	u.Set(comment.FieldLikeCount, v)
	return u
}

// UpdateLikeCount sets the "like_count" field to the value that was provided on create.
func (u *CommentUpsert) UpdateLikeCount() *CommentUpsert {
	u.SetExcluded(comment.FieldLikeCount)
	return u
}

// AddLikeCount adds v to the "like_count" field.
func (u *CommentUpsert) AddLikeCount(v int) *CommentUpsert {
	u.Add(comment.FieldLikeCount, v)
	return u
}

// SetPinnedAt sets the "pinned_at" field.
func (u *CommentUpsert) SetPinnedAt(v time.Time) *CommentUpsert {
	u.Set(comment.FieldPinnedAt, v)
	return u
}

// UpdatePinnedAt sets the "pinned_at" field to the value that was provided on create.
func (u *CommentUpsert) UpdatePinnedAt() *CommentUpsert {
	u.SetExcluded(comment.FieldPinnedAt)
	return u
}

// ClearPinnedAt clears the value of the "pinned_at" field.
func (u *CommentUpsert) ClearPinnedAt() *CommentUpsert {
	u.SetNull(comment.FieldPinnedAt)
	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.Comment.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(comment.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *CommentUpsertOne) UpdateNewValues() *CommentUpsertOne {
	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(comment.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(comment.FieldCreatedAt)
		}
	}))
	return u
}

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

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

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

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

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

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

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

// SetTargetPath sets the "target_path" field.
func (u *CommentUpsertOne) SetTargetPath(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetTargetPath(v)
	})
}

// UpdateTargetPath sets the "target_path" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateTargetPath() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateTargetPath()
	})
}

// SetTargetTitle sets the "target_title" field.
func (u *CommentUpsertOne) SetTargetTitle(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetTargetTitle(v)
	})
}

// UpdateTargetTitle sets the "target_title" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateTargetTitle() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateTargetTitle()
	})
}

// ClearTargetTitle clears the value of the "target_title" field.
func (u *CommentUpsertOne) ClearTargetTitle() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearTargetTitle()
	})
}

// SetUserID sets the "user_id" field.
func (u *CommentUpsertOne) SetUserID(v uint) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetUserID(v)
	})
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateUserID() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateUserID()
	})
}

// ClearUserID clears the value of the "user_id" field.
func (u *CommentUpsertOne) ClearUserID() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearUserID()
	})
}

// SetParentID sets the "parent_id" field.
func (u *CommentUpsertOne) SetParentID(v uint) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetParentID(v)
	})
}

// UpdateParentID sets the "parent_id" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateParentID() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateParentID()
	})
}

// ClearParentID clears the value of the "parent_id" field.
func (u *CommentUpsertOne) ClearParentID() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearParentID()
	})
}

// SetNickname sets the "nickname" field.
func (u *CommentUpsertOne) SetNickname(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetNickname(v)
	})
}

// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateNickname() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateNickname()
	})
}

// SetEmail sets the "email" field.
func (u *CommentUpsertOne) SetEmail(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetEmail(v)
	})
}

// UpdateEmail sets the "email" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateEmail() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateEmail()
	})
}

// ClearEmail clears the value of the "email" field.
func (u *CommentUpsertOne) ClearEmail() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearEmail()
	})
}

// SetEmailMd5 sets the "email_md5" field.
func (u *CommentUpsertOne) SetEmailMd5(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetEmailMd5(v)
	})
}

// UpdateEmailMd5 sets the "email_md5" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateEmailMd5() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateEmailMd5()
	})
}

// SetWebsite sets the "website" field.
func (u *CommentUpsertOne) SetWebsite(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetWebsite(v)
	})
}

// UpdateWebsite sets the "website" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateWebsite() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateWebsite()
	})
}

// ClearWebsite clears the value of the "website" field.
func (u *CommentUpsertOne) ClearWebsite() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearWebsite()
	})
}

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

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

// SetContentHTML sets the "content_html" field.
func (u *CommentUpsertOne) SetContentHTML(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetContentHTML(v)
	})
}

// UpdateContentHTML sets the "content_html" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateContentHTML() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateContentHTML()
	})
}

// SetStatus sets the "status" field.
func (u *CommentUpsertOne) SetStatus(v int) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *CommentUpsertOne) AddStatus(v int) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.AddStatus(v)
	})
}

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

// SetIsAdminComment sets the "is_admin_comment" field.
func (u *CommentUpsertOne) SetIsAdminComment(v bool) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetIsAdminComment(v)
	})
}

// UpdateIsAdminComment sets the "is_admin_comment" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateIsAdminComment() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIsAdminComment()
	})
}

// SetIsAnonymous sets the "is_anonymous" field.
func (u *CommentUpsertOne) SetIsAnonymous(v bool) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetIsAnonymous(v)
	})
}

// UpdateIsAnonymous sets the "is_anonymous" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateIsAnonymous() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIsAnonymous()
	})
}

// SetAllowNotification sets the "allow_notification" field.
func (u *CommentUpsertOne) SetAllowNotification(v bool) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetAllowNotification(v)
	})
}

// UpdateAllowNotification sets the "allow_notification" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateAllowNotification() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateAllowNotification()
	})
}

// SetUserAgent sets the "user_agent" field.
func (u *CommentUpsertOne) SetUserAgent(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetUserAgent(v)
	})
}

// UpdateUserAgent sets the "user_agent" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateUserAgent() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateUserAgent()
	})
}

// ClearUserAgent clears the value of the "user_agent" field.
func (u *CommentUpsertOne) ClearUserAgent() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearUserAgent()
	})
}

// SetIPAddress sets the "ip_address" field.
func (u *CommentUpsertOne) SetIPAddress(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetIPAddress(v)
	})
}

// UpdateIPAddress sets the "ip_address" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateIPAddress() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIPAddress()
	})
}

// SetIPLocation sets the "ip_location" field.
func (u *CommentUpsertOne) SetIPLocation(v string) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetIPLocation(v)
	})
}

// UpdateIPLocation sets the "ip_location" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateIPLocation() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIPLocation()
	})
}

// ClearIPLocation clears the value of the "ip_location" field.
func (u *CommentUpsertOne) ClearIPLocation() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearIPLocation()
	})
}

// SetLikeCount sets the "like_count" field.
func (u *CommentUpsertOne) SetLikeCount(v int) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetLikeCount(v)
	})
}

// AddLikeCount adds v to the "like_count" field.
func (u *CommentUpsertOne) AddLikeCount(v int) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.AddLikeCount(v)
	})
}

// UpdateLikeCount sets the "like_count" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateLikeCount() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateLikeCount()
	})
}

// SetPinnedAt sets the "pinned_at" field.
func (u *CommentUpsertOne) SetPinnedAt(v time.Time) *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.SetPinnedAt(v)
	})
}

// UpdatePinnedAt sets the "pinned_at" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdatePinnedAt() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.UpdatePinnedAt()
	})
}

// ClearPinnedAt clears the value of the "pinned_at" field.
func (u *CommentUpsertOne) ClearPinnedAt() *CommentUpsertOne {
	return u.Update(func(s *CommentUpsert) {
		s.ClearPinnedAt()
	})
}

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

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

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

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

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

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

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

// CommentUpsertBulk is the builder for "upsert"-ing
// a bulk of Comment nodes.
type CommentUpsertBulk struct {
	create *CommentCreateBulk
}

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

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

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

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

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

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

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

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

// SetTargetPath sets the "target_path" field.
func (u *CommentUpsertBulk) SetTargetPath(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetTargetPath(v)
	})
}

// UpdateTargetPath sets the "target_path" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateTargetPath() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateTargetPath()
	})
}

// SetTargetTitle sets the "target_title" field.
func (u *CommentUpsertBulk) SetTargetTitle(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetTargetTitle(v)
	})
}

// UpdateTargetTitle sets the "target_title" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateTargetTitle() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateTargetTitle()
	})
}

// ClearTargetTitle clears the value of the "target_title" field.
func (u *CommentUpsertBulk) ClearTargetTitle() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearTargetTitle()
	})
}

// SetUserID sets the "user_id" field.
func (u *CommentUpsertBulk) SetUserID(v uint) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetUserID(v)
	})
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateUserID() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateUserID()
	})
}

// ClearUserID clears the value of the "user_id" field.
func (u *CommentUpsertBulk) ClearUserID() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearUserID()
	})
}

// SetParentID sets the "parent_id" field.
func (u *CommentUpsertBulk) SetParentID(v uint) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetParentID(v)
	})
}

// UpdateParentID sets the "parent_id" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateParentID() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateParentID()
	})
}

// ClearParentID clears the value of the "parent_id" field.
func (u *CommentUpsertBulk) ClearParentID() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearParentID()
	})
}

// SetNickname sets the "nickname" field.
func (u *CommentUpsertBulk) SetNickname(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetNickname(v)
	})
}

// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateNickname() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateNickname()
	})
}

// SetEmail sets the "email" field.
func (u *CommentUpsertBulk) SetEmail(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetEmail(v)
	})
}

// UpdateEmail sets the "email" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateEmail() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateEmail()
	})
}

// ClearEmail clears the value of the "email" field.
func (u *CommentUpsertBulk) ClearEmail() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearEmail()
	})
}

// SetEmailMd5 sets the "email_md5" field.
func (u *CommentUpsertBulk) SetEmailMd5(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetEmailMd5(v)
	})
}

// UpdateEmailMd5 sets the "email_md5" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateEmailMd5() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateEmailMd5()
	})
}

// SetWebsite sets the "website" field.
func (u *CommentUpsertBulk) SetWebsite(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetWebsite(v)
	})
}

// UpdateWebsite sets the "website" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateWebsite() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateWebsite()
	})
}

// ClearWebsite clears the value of the "website" field.
func (u *CommentUpsertBulk) ClearWebsite() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearWebsite()
	})
}

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

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

// SetContentHTML sets the "content_html" field.
func (u *CommentUpsertBulk) SetContentHTML(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetContentHTML(v)
	})
}

// UpdateContentHTML sets the "content_html" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateContentHTML() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateContentHTML()
	})
}

// SetStatus sets the "status" field.
func (u *CommentUpsertBulk) SetStatus(v int) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *CommentUpsertBulk) AddStatus(v int) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.AddStatus(v)
	})
}

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

// SetIsAdminComment sets the "is_admin_comment" field.
func (u *CommentUpsertBulk) SetIsAdminComment(v bool) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetIsAdminComment(v)
	})
}

// UpdateIsAdminComment sets the "is_admin_comment" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateIsAdminComment() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIsAdminComment()
	})
}

// SetIsAnonymous sets the "is_anonymous" field.
func (u *CommentUpsertBulk) SetIsAnonymous(v bool) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetIsAnonymous(v)
	})
}

// UpdateIsAnonymous sets the "is_anonymous" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateIsAnonymous() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIsAnonymous()
	})
}

// SetAllowNotification sets the "allow_notification" field.
func (u *CommentUpsertBulk) SetAllowNotification(v bool) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetAllowNotification(v)
	})
}

// UpdateAllowNotification sets the "allow_notification" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateAllowNotification() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateAllowNotification()
	})
}

// SetUserAgent sets the "user_agent" field.
func (u *CommentUpsertBulk) SetUserAgent(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetUserAgent(v)
	})
}

// UpdateUserAgent sets the "user_agent" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateUserAgent() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateUserAgent()
	})
}

// ClearUserAgent clears the value of the "user_agent" field.
func (u *CommentUpsertBulk) ClearUserAgent() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearUserAgent()
	})
}

// SetIPAddress sets the "ip_address" field.
func (u *CommentUpsertBulk) SetIPAddress(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetIPAddress(v)
	})
}

// UpdateIPAddress sets the "ip_address" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateIPAddress() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIPAddress()
	})
}

// SetIPLocation sets the "ip_location" field.
func (u *CommentUpsertBulk) SetIPLocation(v string) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetIPLocation(v)
	})
}

// UpdateIPLocation sets the "ip_location" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateIPLocation() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateIPLocation()
	})
}

// ClearIPLocation clears the value of the "ip_location" field.
func (u *CommentUpsertBulk) ClearIPLocation() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearIPLocation()
	})
}

// SetLikeCount sets the "like_count" field.
func (u *CommentUpsertBulk) SetLikeCount(v int) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetLikeCount(v)
	})
}

// AddLikeCount adds v to the "like_count" field.
func (u *CommentUpsertBulk) AddLikeCount(v int) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.AddLikeCount(v)
	})
}

// UpdateLikeCount sets the "like_count" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateLikeCount() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdateLikeCount()
	})
}

// SetPinnedAt sets the "pinned_at" field.
func (u *CommentUpsertBulk) SetPinnedAt(v time.Time) *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.SetPinnedAt(v)
	})
}

// UpdatePinnedAt sets the "pinned_at" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdatePinnedAt() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.UpdatePinnedAt()
	})
}

// ClearPinnedAt clears the value of the "pinned_at" field.
func (u *CommentUpsertBulk) ClearPinnedAt() *CommentUpsertBulk {
	return u.Update(func(s *CommentUpsert) {
		s.ClearPinnedAt()
	})
}

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

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