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

// CommentUpdate is the builder for updating Comment entities.
type CommentUpdate struct {
	config
	hooks     []Hook
	mutation  *CommentMutation
	modifiers []func(*sql.UpdateBuilder)
}

// Where appends a list predicates to the CommentUpdate builder.
func (_u *CommentUpdate) Where(ps ...predicate.Comment) *CommentUpdate {
	_u.mutation.Where(ps...)
	return _u
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *CommentUpdate) ClearDeletedAt() *CommentUpdate {
	_u.mutation.ClearDeletedAt()
	return _u
}

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

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

// SetNillableTargetPath sets the "target_path" field if the given value is not nil.
func (_u *CommentUpdate) SetNillableTargetPath(v *string) *CommentUpdate {
	if v != nil {
		_u.SetTargetPath(*v)
	}
	return _u
}

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

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

// ClearTargetTitle clears the value of the "target_title" field.
func (_u *CommentUpdate) ClearTargetTitle() *CommentUpdate {
	_u.mutation.ClearTargetTitle()
	return _u
}

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

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

// ClearUserID clears the value of the "user_id" field.
func (_u *CommentUpdate) ClearUserID() *CommentUpdate {
	_u.mutation.ClearUserID()
	return _u
}

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

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

// ClearParentID clears the value of the "parent_id" field.
func (_u *CommentUpdate) ClearParentID() *CommentUpdate {
	_u.mutation.ClearParentID()
	return _u
}

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

// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (_u *CommentUpdate) SetNillableNickname(v *string) *CommentUpdate {
	if v != nil {
		_u.SetNickname(*v)
	}
	return _u
}

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

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

// ClearEmail clears the value of the "email" field.
func (_u *CommentUpdate) ClearEmail() *CommentUpdate {
	_u.mutation.ClearEmail()
	return _u
}

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

// SetNillableEmailMd5 sets the "email_md5" field if the given value is not nil.
func (_u *CommentUpdate) SetNillableEmailMd5(v *string) *CommentUpdate {
	if v != nil {
		_u.SetEmailMd5(*v)
	}
	return _u
}

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

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

// ClearWebsite clears the value of the "website" field.
func (_u *CommentUpdate) ClearWebsite() *CommentUpdate {
	_u.mutation.ClearWebsite()
	return _u
}

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

// SetNillableContent sets the "content" field if the given value is not nil.
func (_u *CommentUpdate) SetNillableContent(v *string) *CommentUpdate {
	if v != nil {
		_u.SetContent(*v)
	}
	return _u
}

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

// SetNillableContentHTML sets the "content_html" field if the given value is not nil.
func (_u *CommentUpdate) SetNillableContentHTML(v *string) *CommentUpdate {
	if v != nil {
		_u.SetContentHTML(*v)
	}
	return _u
}

// SetStatus sets the "status" field.
func (_u *CommentUpdate) SetStatus(v int) *CommentUpdate {
	_u.mutation.ResetStatus()
	_u.mutation.SetStatus(v)
	return _u
}

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

// AddStatus adds value to the "status" field.
func (_u *CommentUpdate) AddStatus(v int) *CommentUpdate {
	_u.mutation.AddStatus(v)
	return _u
}

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

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

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

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

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

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

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

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

// ClearUserAgent clears the value of the "user_agent" field.
func (_u *CommentUpdate) ClearUserAgent() *CommentUpdate {
	_u.mutation.ClearUserAgent()
	return _u
}

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

// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
func (_u *CommentUpdate) SetNillableIPAddress(v *string) *CommentUpdate {
	if v != nil {
		_u.SetIPAddress(*v)
	}
	return _u
}

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

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

// ClearIPLocation clears the value of the "ip_location" field.
func (_u *CommentUpdate) ClearIPLocation() *CommentUpdate {
	_u.mutation.ClearIPLocation()
	return _u
}

// SetLikeCount sets the "like_count" field.
func (_u *CommentUpdate) SetLikeCount(v int) *CommentUpdate {
	_u.mutation.ResetLikeCount()
	_u.mutation.SetLikeCount(v)
	return _u
}

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

// AddLikeCount adds value to the "like_count" field.
func (_u *CommentUpdate) AddLikeCount(v int) *CommentUpdate {
	_u.mutation.AddLikeCount(v)
	return _u
}

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

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

// ClearPinnedAt clears the value of the "pinned_at" field.
func (_u *CommentUpdate) ClearPinnedAt() *CommentUpdate {
	_u.mutation.ClearPinnedAt()
	return _u
}

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

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

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

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

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

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

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

// ClearUser clears the "user" edge to the User entity.
func (_u *CommentUpdate) ClearUser() *CommentUpdate {
	_u.mutation.ClearUser()
	return _u
}

// ClearChildren clears the "children" edge to the Comment entity.
func (_u *CommentUpdate) ClearChildren() *CommentUpdate {
	_u.mutation.ClearChildren()
	return _u
}

// ClearParent clears all "parent" edges to the Comment entity.
func (_u *CommentUpdate) ClearParent() *CommentUpdate {
	_u.mutation.ClearParent()
	return _u
}

// RemoveParentIDs removes the "parent" edge to Comment entities by IDs.
func (_u *CommentUpdate) RemoveParentIDs(ids ...uint) *CommentUpdate {
	_u.mutation.RemoveParentIDs(ids...)
	return _u
}

// RemoveParent removes "parent" edges to Comment entities.
func (_u *CommentUpdate) RemoveParent(v ...*Comment) *CommentUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveParentIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *CommentUpdate) Save(ctx context.Context) (int, error) {
	if err := _u.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (_u *CommentUpdate) SaveX(ctx context.Context) int {
	affected, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

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

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

// defaults sets the default values of the builder before save.
func (_u *CommentUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if comment.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized comment.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := comment.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *CommentUpdate) check() error {
	if v, ok := _u.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 := _u.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 v, ok := _u.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 := _u.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 v, ok := _u.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 := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 := _u.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 v, ok := _u.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
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *CommentUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CommentUpdate {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *CommentUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(comment.Table, comment.Columns, sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(comment.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(comment.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(comment.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.TargetPath(); ok {
		_spec.SetField(comment.FieldTargetPath, field.TypeString, value)
	}
	if value, ok := _u.mutation.TargetTitle(); ok {
		_spec.SetField(comment.FieldTargetTitle, field.TypeString, value)
	}
	if _u.mutation.TargetTitleCleared() {
		_spec.ClearField(comment.FieldTargetTitle, field.TypeString)
	}
	if value, ok := _u.mutation.Nickname(); ok {
		_spec.SetField(comment.FieldNickname, field.TypeString, value)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(comment.FieldEmail, field.TypeString, value)
	}
	if _u.mutation.EmailCleared() {
		_spec.ClearField(comment.FieldEmail, field.TypeString)
	}
	if value, ok := _u.mutation.EmailMd5(); ok {
		_spec.SetField(comment.FieldEmailMd5, field.TypeString, value)
	}
	if value, ok := _u.mutation.Website(); ok {
		_spec.SetField(comment.FieldWebsite, field.TypeString, value)
	}
	if _u.mutation.WebsiteCleared() {
		_spec.ClearField(comment.FieldWebsite, field.TypeString)
	}
	if value, ok := _u.mutation.Content(); ok {
		_spec.SetField(comment.FieldContent, field.TypeString, value)
	}
	if value, ok := _u.mutation.ContentHTML(); ok {
		_spec.SetField(comment.FieldContentHTML, field.TypeString, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(comment.FieldStatus, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedStatus(); ok {
		_spec.AddField(comment.FieldStatus, field.TypeInt, value)
	}
	if value, ok := _u.mutation.IsAdminComment(); ok {
		_spec.SetField(comment.FieldIsAdminComment, field.TypeBool, value)
	}
	if value, ok := _u.mutation.IsAnonymous(); ok {
		_spec.SetField(comment.FieldIsAnonymous, field.TypeBool, value)
	}
	if value, ok := _u.mutation.AllowNotification(); ok {
		_spec.SetField(comment.FieldAllowNotification, field.TypeBool, value)
	}
	if value, ok := _u.mutation.UserAgent(); ok {
		_spec.SetField(comment.FieldUserAgent, field.TypeString, value)
	}
	if _u.mutation.UserAgentCleared() {
		_spec.ClearField(comment.FieldUserAgent, field.TypeString)
	}
	if value, ok := _u.mutation.IPAddress(); ok {
		_spec.SetField(comment.FieldIPAddress, field.TypeString, value)
	}
	if value, ok := _u.mutation.IPLocation(); ok {
		_spec.SetField(comment.FieldIPLocation, field.TypeString, value)
	}
	if _u.mutation.IPLocationCleared() {
		_spec.ClearField(comment.FieldIPLocation, field.TypeString)
	}
	if value, ok := _u.mutation.LikeCount(); ok {
		_spec.SetField(comment.FieldLikeCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedLikeCount(); ok {
		_spec.AddField(comment.FieldLikeCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.PinnedAt(); ok {
		_spec.SetField(comment.FieldPinnedAt, field.TypeTime, value)
	}
	if _u.mutation.PinnedAtCleared() {
		_spec.ClearField(comment.FieldPinnedAt, field.TypeTime)
	}
	if _u.mutation.UserCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ChildrenCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ParentCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedParentIDs(); len(nodes) > 0 && !_u.mutation.ParentCleared() {
		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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.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.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{comment.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// CommentUpdateOne is the builder for updating a single Comment entity.
type CommentUpdateOne struct {
	config
	fields    []string
	hooks     []Hook
	mutation  *CommentMutation
	modifiers []func(*sql.UpdateBuilder)
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *CommentUpdateOne) ClearDeletedAt() *CommentUpdateOne {
	_u.mutation.ClearDeletedAt()
	return _u
}

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

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

// SetNillableTargetPath sets the "target_path" field if the given value is not nil.
func (_u *CommentUpdateOne) SetNillableTargetPath(v *string) *CommentUpdateOne {
	if v != nil {
		_u.SetTargetPath(*v)
	}
	return _u
}

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

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

// ClearTargetTitle clears the value of the "target_title" field.
func (_u *CommentUpdateOne) ClearTargetTitle() *CommentUpdateOne {
	_u.mutation.ClearTargetTitle()
	return _u
}

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

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

// ClearUserID clears the value of the "user_id" field.
func (_u *CommentUpdateOne) ClearUserID() *CommentUpdateOne {
	_u.mutation.ClearUserID()
	return _u
}

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

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

// ClearParentID clears the value of the "parent_id" field.
func (_u *CommentUpdateOne) ClearParentID() *CommentUpdateOne {
	_u.mutation.ClearParentID()
	return _u
}

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

// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (_u *CommentUpdateOne) SetNillableNickname(v *string) *CommentUpdateOne {
	if v != nil {
		_u.SetNickname(*v)
	}
	return _u
}

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

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

// ClearEmail clears the value of the "email" field.
func (_u *CommentUpdateOne) ClearEmail() *CommentUpdateOne {
	_u.mutation.ClearEmail()
	return _u
}

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

// SetNillableEmailMd5 sets the "email_md5" field if the given value is not nil.
func (_u *CommentUpdateOne) SetNillableEmailMd5(v *string) *CommentUpdateOne {
	if v != nil {
		_u.SetEmailMd5(*v)
	}
	return _u
}

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

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

// ClearWebsite clears the value of the "website" field.
func (_u *CommentUpdateOne) ClearWebsite() *CommentUpdateOne {
	_u.mutation.ClearWebsite()
	return _u
}

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

// SetNillableContent sets the "content" field if the given value is not nil.
func (_u *CommentUpdateOne) SetNillableContent(v *string) *CommentUpdateOne {
	if v != nil {
		_u.SetContent(*v)
	}
	return _u
}

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

// SetNillableContentHTML sets the "content_html" field if the given value is not nil.
func (_u *CommentUpdateOne) SetNillableContentHTML(v *string) *CommentUpdateOne {
	if v != nil {
		_u.SetContentHTML(*v)
	}
	return _u
}

// SetStatus sets the "status" field.
func (_u *CommentUpdateOne) SetStatus(v int) *CommentUpdateOne {
	_u.mutation.ResetStatus()
	_u.mutation.SetStatus(v)
	return _u
}

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

// AddStatus adds value to the "status" field.
func (_u *CommentUpdateOne) AddStatus(v int) *CommentUpdateOne {
	_u.mutation.AddStatus(v)
	return _u
}

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

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

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

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

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

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

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

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

// ClearUserAgent clears the value of the "user_agent" field.
func (_u *CommentUpdateOne) ClearUserAgent() *CommentUpdateOne {
	_u.mutation.ClearUserAgent()
	return _u
}

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

// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
func (_u *CommentUpdateOne) SetNillableIPAddress(v *string) *CommentUpdateOne {
	if v != nil {
		_u.SetIPAddress(*v)
	}
	return _u
}

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

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

// ClearIPLocation clears the value of the "ip_location" field.
func (_u *CommentUpdateOne) ClearIPLocation() *CommentUpdateOne {
	_u.mutation.ClearIPLocation()
	return _u
}

// SetLikeCount sets the "like_count" field.
func (_u *CommentUpdateOne) SetLikeCount(v int) *CommentUpdateOne {
	_u.mutation.ResetLikeCount()
	_u.mutation.SetLikeCount(v)
	return _u
}

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

// AddLikeCount adds value to the "like_count" field.
func (_u *CommentUpdateOne) AddLikeCount(v int) *CommentUpdateOne {
	_u.mutation.AddLikeCount(v)
	return _u
}

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

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

// ClearPinnedAt clears the value of the "pinned_at" field.
func (_u *CommentUpdateOne) ClearPinnedAt() *CommentUpdateOne {
	_u.mutation.ClearPinnedAt()
	return _u
}

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

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

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

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

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

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

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

// ClearUser clears the "user" edge to the User entity.
func (_u *CommentUpdateOne) ClearUser() *CommentUpdateOne {
	_u.mutation.ClearUser()
	return _u
}

// ClearChildren clears the "children" edge to the Comment entity.
func (_u *CommentUpdateOne) ClearChildren() *CommentUpdateOne {
	_u.mutation.ClearChildren()
	return _u
}

// ClearParent clears all "parent" edges to the Comment entity.
func (_u *CommentUpdateOne) ClearParent() *CommentUpdateOne {
	_u.mutation.ClearParent()
	return _u
}

// RemoveParentIDs removes the "parent" edge to Comment entities by IDs.
func (_u *CommentUpdateOne) RemoveParentIDs(ids ...uint) *CommentUpdateOne {
	_u.mutation.RemoveParentIDs(ids...)
	return _u
}

// RemoveParent removes "parent" edges to Comment entities.
func (_u *CommentUpdateOne) RemoveParent(v ...*Comment) *CommentUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveParentIDs(ids...)
}

// Where appends a list predicates to the CommentUpdate builder.
func (_u *CommentUpdateOne) Where(ps ...predicate.Comment) *CommentUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *CommentUpdateOne) Select(field string, fields ...string) *CommentUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

// Save executes the query and returns the updated Comment entity.
func (_u *CommentUpdateOne) Save(ctx context.Context) (*Comment, error) {
	if err := _u.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (_u *CommentUpdateOne) SaveX(ctx context.Context) *Comment {
	node, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (_u *CommentUpdateOne) Exec(ctx context.Context) error {
	_, err := _u.Save(ctx)
	return err
}

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

// defaults sets the default values of the builder before save.
func (_u *CommentUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if comment.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized comment.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := comment.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *CommentUpdateOne) check() error {
	if v, ok := _u.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 := _u.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 v, ok := _u.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 := _u.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 v, ok := _u.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 := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 := _u.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 v, ok := _u.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
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *CommentUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CommentUpdateOne {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(comment.Table, comment.Columns, sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Comment.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, comment.FieldID)
		for _, f := range fields {
			if !comment.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != comment.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(comment.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(comment.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(comment.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.TargetPath(); ok {
		_spec.SetField(comment.FieldTargetPath, field.TypeString, value)
	}
	if value, ok := _u.mutation.TargetTitle(); ok {
		_spec.SetField(comment.FieldTargetTitle, field.TypeString, value)
	}
	if _u.mutation.TargetTitleCleared() {
		_spec.ClearField(comment.FieldTargetTitle, field.TypeString)
	}
	if value, ok := _u.mutation.Nickname(); ok {
		_spec.SetField(comment.FieldNickname, field.TypeString, value)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(comment.FieldEmail, field.TypeString, value)
	}
	if _u.mutation.EmailCleared() {
		_spec.ClearField(comment.FieldEmail, field.TypeString)
	}
	if value, ok := _u.mutation.EmailMd5(); ok {
		_spec.SetField(comment.FieldEmailMd5, field.TypeString, value)
	}
	if value, ok := _u.mutation.Website(); ok {
		_spec.SetField(comment.FieldWebsite, field.TypeString, value)
	}
	if _u.mutation.WebsiteCleared() {
		_spec.ClearField(comment.FieldWebsite, field.TypeString)
	}
	if value, ok := _u.mutation.Content(); ok {
		_spec.SetField(comment.FieldContent, field.TypeString, value)
	}
	if value, ok := _u.mutation.ContentHTML(); ok {
		_spec.SetField(comment.FieldContentHTML, field.TypeString, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(comment.FieldStatus, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedStatus(); ok {
		_spec.AddField(comment.FieldStatus, field.TypeInt, value)
	}
	if value, ok := _u.mutation.IsAdminComment(); ok {
		_spec.SetField(comment.FieldIsAdminComment, field.TypeBool, value)
	}
	if value, ok := _u.mutation.IsAnonymous(); ok {
		_spec.SetField(comment.FieldIsAnonymous, field.TypeBool, value)
	}
	if value, ok := _u.mutation.AllowNotification(); ok {
		_spec.SetField(comment.FieldAllowNotification, field.TypeBool, value)
	}
	if value, ok := _u.mutation.UserAgent(); ok {
		_spec.SetField(comment.FieldUserAgent, field.TypeString, value)
	}
	if _u.mutation.UserAgentCleared() {
		_spec.ClearField(comment.FieldUserAgent, field.TypeString)
	}
	if value, ok := _u.mutation.IPAddress(); ok {
		_spec.SetField(comment.FieldIPAddress, field.TypeString, value)
	}
	if value, ok := _u.mutation.IPLocation(); ok {
		_spec.SetField(comment.FieldIPLocation, field.TypeString, value)
	}
	if _u.mutation.IPLocationCleared() {
		_spec.ClearField(comment.FieldIPLocation, field.TypeString)
	}
	if value, ok := _u.mutation.LikeCount(); ok {
		_spec.SetField(comment.FieldLikeCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedLikeCount(); ok {
		_spec.AddField(comment.FieldLikeCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.PinnedAt(); ok {
		_spec.SetField(comment.FieldPinnedAt, field.TypeTime, value)
	}
	if _u.mutation.PinnedAtCleared() {
		_spec.ClearField(comment.FieldPinnedAt, field.TypeTime)
	}
	if _u.mutation.UserCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ChildrenCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.ParentCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedParentIDs(); len(nodes) > 0 && !_u.mutation.ParentCleared() {
		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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.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.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	_node = &Comment{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{comment.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
