// 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/dialect/sql/sqljson"
	"entgo.io/ent/schema/field"
	"github.com/anzhiyu-c/anheyu-app/ent/article"
	"github.com/anzhiyu-c/anheyu-app/ent/comment"
	"github.com/anzhiyu-c/anheyu-app/ent/postcategory"
	"github.com/anzhiyu-c/anheyu-app/ent/posttag"
	"github.com/anzhiyu-c/anheyu-app/ent/predicate"
)

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

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

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

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

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

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

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

// SetNillableTitle sets the "title" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableTitle(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetTitle(*v)
	}
	return _u
}

// SetContentMd sets the "content_md" field.
func (_u *ArticleUpdate) SetContentMd(v string) *ArticleUpdate {
	_u.mutation.SetContentMd(v)
	return _u
}

// SetNillableContentMd sets the "content_md" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableContentMd(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetContentMd(*v)
	}
	return _u
}

// ClearContentMd clears the value of the "content_md" field.
func (_u *ArticleUpdate) ClearContentMd() *ArticleUpdate {
	_u.mutation.ClearContentMd()
	return _u
}

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

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

// ClearContentHTML clears the value of the "content_html" field.
func (_u *ArticleUpdate) ClearContentHTML() *ArticleUpdate {
	_u.mutation.ClearContentHTML()
	return _u
}

// SetCoverURL sets the "cover_url" field.
func (_u *ArticleUpdate) SetCoverURL(v string) *ArticleUpdate {
	_u.mutation.SetCoverURL(v)
	return _u
}

// SetNillableCoverURL sets the "cover_url" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableCoverURL(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetCoverURL(*v)
	}
	return _u
}

// ClearCoverURL clears the value of the "cover_url" field.
func (_u *ArticleUpdate) ClearCoverURL() *ArticleUpdate {
	_u.mutation.ClearCoverURL()
	return _u
}

// SetStatus sets the "status" field.
func (_u *ArticleUpdate) SetStatus(v article.Status) *ArticleUpdate {
	_u.mutation.SetStatus(v)
	return _u
}

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

// SetViewCount sets the "view_count" field.
func (_u *ArticleUpdate) SetViewCount(v int) *ArticleUpdate {
	_u.mutation.ResetViewCount()
	_u.mutation.SetViewCount(v)
	return _u
}

// SetNillableViewCount sets the "view_count" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableViewCount(v *int) *ArticleUpdate {
	if v != nil {
		_u.SetViewCount(*v)
	}
	return _u
}

// AddViewCount adds value to the "view_count" field.
func (_u *ArticleUpdate) AddViewCount(v int) *ArticleUpdate {
	_u.mutation.AddViewCount(v)
	return _u
}

// SetWordCount sets the "word_count" field.
func (_u *ArticleUpdate) SetWordCount(v int) *ArticleUpdate {
	_u.mutation.ResetWordCount()
	_u.mutation.SetWordCount(v)
	return _u
}

// SetNillableWordCount sets the "word_count" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableWordCount(v *int) *ArticleUpdate {
	if v != nil {
		_u.SetWordCount(*v)
	}
	return _u
}

// AddWordCount adds value to the "word_count" field.
func (_u *ArticleUpdate) AddWordCount(v int) *ArticleUpdate {
	_u.mutation.AddWordCount(v)
	return _u
}

// SetReadingTime sets the "reading_time" field.
func (_u *ArticleUpdate) SetReadingTime(v int) *ArticleUpdate {
	_u.mutation.ResetReadingTime()
	_u.mutation.SetReadingTime(v)
	return _u
}

// SetNillableReadingTime sets the "reading_time" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableReadingTime(v *int) *ArticleUpdate {
	if v != nil {
		_u.SetReadingTime(*v)
	}
	return _u
}

// AddReadingTime adds value to the "reading_time" field.
func (_u *ArticleUpdate) AddReadingTime(v int) *ArticleUpdate {
	_u.mutation.AddReadingTime(v)
	return _u
}

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

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

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

// SetPrimaryColor sets the "primary_color" field.
func (_u *ArticleUpdate) SetPrimaryColor(v string) *ArticleUpdate {
	_u.mutation.SetPrimaryColor(v)
	return _u
}

// SetNillablePrimaryColor sets the "primary_color" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillablePrimaryColor(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetPrimaryColor(*v)
	}
	return _u
}

// ClearPrimaryColor clears the value of the "primary_color" field.
func (_u *ArticleUpdate) ClearPrimaryColor() *ArticleUpdate {
	_u.mutation.ClearPrimaryColor()
	return _u
}

// SetIsPrimaryColorManual sets the "is_primary_color_manual" field.
func (_u *ArticleUpdate) SetIsPrimaryColorManual(v bool) *ArticleUpdate {
	_u.mutation.SetIsPrimaryColorManual(v)
	return _u
}

// SetNillableIsPrimaryColorManual sets the "is_primary_color_manual" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableIsPrimaryColorManual(v *bool) *ArticleUpdate {
	if v != nil {
		_u.SetIsPrimaryColorManual(*v)
	}
	return _u
}

// SetHomeSort sets the "home_sort" field.
func (_u *ArticleUpdate) SetHomeSort(v int) *ArticleUpdate {
	_u.mutation.ResetHomeSort()
	_u.mutation.SetHomeSort(v)
	return _u
}

// SetNillableHomeSort sets the "home_sort" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableHomeSort(v *int) *ArticleUpdate {
	if v != nil {
		_u.SetHomeSort(*v)
	}
	return _u
}

// AddHomeSort adds value to the "home_sort" field.
func (_u *ArticleUpdate) AddHomeSort(v int) *ArticleUpdate {
	_u.mutation.AddHomeSort(v)
	return _u
}

// SetPinSort sets the "pin_sort" field.
func (_u *ArticleUpdate) SetPinSort(v int) *ArticleUpdate {
	_u.mutation.ResetPinSort()
	_u.mutation.SetPinSort(v)
	return _u
}

// SetNillablePinSort sets the "pin_sort" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillablePinSort(v *int) *ArticleUpdate {
	if v != nil {
		_u.SetPinSort(*v)
	}
	return _u
}

// AddPinSort adds value to the "pin_sort" field.
func (_u *ArticleUpdate) AddPinSort(v int) *ArticleUpdate {
	_u.mutation.AddPinSort(v)
	return _u
}

// SetTopImgURL sets the "top_img_url" field.
func (_u *ArticleUpdate) SetTopImgURL(v string) *ArticleUpdate {
	_u.mutation.SetTopImgURL(v)
	return _u
}

// SetNillableTopImgURL sets the "top_img_url" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableTopImgURL(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetTopImgURL(*v)
	}
	return _u
}

// ClearTopImgURL clears the value of the "top_img_url" field.
func (_u *ArticleUpdate) ClearTopImgURL() *ArticleUpdate {
	_u.mutation.ClearTopImgURL()
	return _u
}

// SetSummaries sets the "summaries" field.
func (_u *ArticleUpdate) SetSummaries(v []string) *ArticleUpdate {
	_u.mutation.SetSummaries(v)
	return _u
}

// AppendSummaries appends value to the "summaries" field.
func (_u *ArticleUpdate) AppendSummaries(v []string) *ArticleUpdate {
	_u.mutation.AppendSummaries(v)
	return _u
}

// ClearSummaries clears the value of the "summaries" field.
func (_u *ArticleUpdate) ClearSummaries() *ArticleUpdate {
	_u.mutation.ClearSummaries()
	return _u
}

// SetAbbrlink sets the "abbrlink" field.
func (_u *ArticleUpdate) SetAbbrlink(v string) *ArticleUpdate {
	_u.mutation.SetAbbrlink(v)
	return _u
}

// SetNillableAbbrlink sets the "abbrlink" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableAbbrlink(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetAbbrlink(*v)
	}
	return _u
}

// ClearAbbrlink clears the value of the "abbrlink" field.
func (_u *ArticleUpdate) ClearAbbrlink() *ArticleUpdate {
	_u.mutation.ClearAbbrlink()
	return _u
}

// SetCopyright sets the "copyright" field.
func (_u *ArticleUpdate) SetCopyright(v bool) *ArticleUpdate {
	_u.mutation.SetCopyright(v)
	return _u
}

// SetNillableCopyright sets the "copyright" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableCopyright(v *bool) *ArticleUpdate {
	if v != nil {
		_u.SetCopyright(*v)
	}
	return _u
}

// SetCopyrightAuthor sets the "copyright_author" field.
func (_u *ArticleUpdate) SetCopyrightAuthor(v string) *ArticleUpdate {
	_u.mutation.SetCopyrightAuthor(v)
	return _u
}

// SetNillableCopyrightAuthor sets the "copyright_author" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableCopyrightAuthor(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetCopyrightAuthor(*v)
	}
	return _u
}

// ClearCopyrightAuthor clears the value of the "copyright_author" field.
func (_u *ArticleUpdate) ClearCopyrightAuthor() *ArticleUpdate {
	_u.mutation.ClearCopyrightAuthor()
	return _u
}

// SetCopyrightAuthorHref sets the "copyright_author_href" field.
func (_u *ArticleUpdate) SetCopyrightAuthorHref(v string) *ArticleUpdate {
	_u.mutation.SetCopyrightAuthorHref(v)
	return _u
}

// SetNillableCopyrightAuthorHref sets the "copyright_author_href" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableCopyrightAuthorHref(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetCopyrightAuthorHref(*v)
	}
	return _u
}

// ClearCopyrightAuthorHref clears the value of the "copyright_author_href" field.
func (_u *ArticleUpdate) ClearCopyrightAuthorHref() *ArticleUpdate {
	_u.mutation.ClearCopyrightAuthorHref()
	return _u
}

// SetCopyrightURL sets the "copyright_url" field.
func (_u *ArticleUpdate) SetCopyrightURL(v string) *ArticleUpdate {
	_u.mutation.SetCopyrightURL(v)
	return _u
}

// SetNillableCopyrightURL sets the "copyright_url" field if the given value is not nil.
func (_u *ArticleUpdate) SetNillableCopyrightURL(v *string) *ArticleUpdate {
	if v != nil {
		_u.SetCopyrightURL(*v)
	}
	return _u
}

// ClearCopyrightURL clears the value of the "copyright_url" field.
func (_u *ArticleUpdate) ClearCopyrightURL() *ArticleUpdate {
	_u.mutation.ClearCopyrightURL()
	return _u
}

// AddPostTagIDs adds the "post_tags" edge to the PostTag entity by IDs.
func (_u *ArticleUpdate) AddPostTagIDs(ids ...uint) *ArticleUpdate {
	_u.mutation.AddPostTagIDs(ids...)
	return _u
}

// AddPostTags adds the "post_tags" edges to the PostTag entity.
func (_u *ArticleUpdate) AddPostTags(v ...*PostTag) *ArticleUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPostTagIDs(ids...)
}

// AddPostCategoryIDs adds the "post_categories" edge to the PostCategory entity by IDs.
func (_u *ArticleUpdate) AddPostCategoryIDs(ids ...uint) *ArticleUpdate {
	_u.mutation.AddPostCategoryIDs(ids...)
	return _u
}

// AddPostCategories adds the "post_categories" edges to the PostCategory entity.
func (_u *ArticleUpdate) AddPostCategories(v ...*PostCategory) *ArticleUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPostCategoryIDs(ids...)
}

// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
func (_u *ArticleUpdate) AddCommentIDs(ids ...uint) *ArticleUpdate {
	_u.mutation.AddCommentIDs(ids...)
	return _u
}

// AddComments adds the "comments" edges to the Comment entity.
func (_u *ArticleUpdate) AddComments(v ...*Comment) *ArticleUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddCommentIDs(ids...)
}

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

// ClearPostTags clears all "post_tags" edges to the PostTag entity.
func (_u *ArticleUpdate) ClearPostTags() *ArticleUpdate {
	_u.mutation.ClearPostTags()
	return _u
}

// RemovePostTagIDs removes the "post_tags" edge to PostTag entities by IDs.
func (_u *ArticleUpdate) RemovePostTagIDs(ids ...uint) *ArticleUpdate {
	_u.mutation.RemovePostTagIDs(ids...)
	return _u
}

// RemovePostTags removes "post_tags" edges to PostTag entities.
func (_u *ArticleUpdate) RemovePostTags(v ...*PostTag) *ArticleUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePostTagIDs(ids...)
}

// ClearPostCategories clears all "post_categories" edges to the PostCategory entity.
func (_u *ArticleUpdate) ClearPostCategories() *ArticleUpdate {
	_u.mutation.ClearPostCategories()
	return _u
}

// RemovePostCategoryIDs removes the "post_categories" edge to PostCategory entities by IDs.
func (_u *ArticleUpdate) RemovePostCategoryIDs(ids ...uint) *ArticleUpdate {
	_u.mutation.RemovePostCategoryIDs(ids...)
	return _u
}

// RemovePostCategories removes "post_categories" edges to PostCategory entities.
func (_u *ArticleUpdate) RemovePostCategories(v ...*PostCategory) *ArticleUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePostCategoryIDs(ids...)
}

// ClearComments clears all "comments" edges to the Comment entity.
func (_u *ArticleUpdate) ClearComments() *ArticleUpdate {
	_u.mutation.ClearComments()
	return _u
}

// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
func (_u *ArticleUpdate) RemoveCommentIDs(ids ...uint) *ArticleUpdate {
	_u.mutation.RemoveCommentIDs(ids...)
	return _u
}

// RemoveComments removes "comments" edges to Comment entities.
func (_u *ArticleUpdate) RemoveComments(v ...*Comment) *ArticleUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveCommentIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ArticleUpdate) 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 *ArticleUpdate) SaveX(ctx context.Context) int {
	affected, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *ArticleUpdate) 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 *ArticleUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if article.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized article.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := article.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *ArticleUpdate) check() error {
	if v, ok := _u.mutation.Title(); ok {
		if err := article.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Article.title": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := article.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Article.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ViewCount(); ok {
		if err := article.ViewCountValidator(v); err != nil {
			return &ValidationError{Name: "view_count", err: fmt.Errorf(`ent: validator failed for field "Article.view_count": %w`, err)}
		}
	}
	if v, ok := _u.mutation.WordCount(); ok {
		if err := article.WordCountValidator(v); err != nil {
			return &ValidationError{Name: "word_count", err: fmt.Errorf(`ent: validator failed for field "Article.word_count": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ReadingTime(); ok {
		if err := article.ReadingTimeValidator(v); err != nil {
			return &ValidationError{Name: "reading_time", err: fmt.Errorf(`ent: validator failed for field "Article.reading_time": %w`, err)}
		}
	}
	if v, ok := _u.mutation.HomeSort(); ok {
		if err := article.HomeSortValidator(v); err != nil {
			return &ValidationError{Name: "home_sort", err: fmt.Errorf(`ent: validator failed for field "Article.home_sort": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PinSort(); ok {
		if err := article.PinSortValidator(v); err != nil {
			return &ValidationError{Name: "pin_sort", err: fmt.Errorf(`ent: validator failed for field "Article.pin_sort": %w`, err)}
		}
	}
	return nil
}

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

func (_u *ArticleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(article.Table, article.Columns, sqlgraph.NewFieldSpec(article.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(article.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(article.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(article.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Title(); ok {
		_spec.SetField(article.FieldTitle, field.TypeString, value)
	}
	if value, ok := _u.mutation.ContentMd(); ok {
		_spec.SetField(article.FieldContentMd, field.TypeString, value)
	}
	if _u.mutation.ContentMdCleared() {
		_spec.ClearField(article.FieldContentMd, field.TypeString)
	}
	if value, ok := _u.mutation.ContentHTML(); ok {
		_spec.SetField(article.FieldContentHTML, field.TypeString, value)
	}
	if _u.mutation.ContentHTMLCleared() {
		_spec.ClearField(article.FieldContentHTML, field.TypeString)
	}
	if value, ok := _u.mutation.CoverURL(); ok {
		_spec.SetField(article.FieldCoverURL, field.TypeString, value)
	}
	if _u.mutation.CoverURLCleared() {
		_spec.ClearField(article.FieldCoverURL, field.TypeString)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(article.FieldStatus, field.TypeEnum, value)
	}
	if value, ok := _u.mutation.ViewCount(); ok {
		_spec.SetField(article.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedViewCount(); ok {
		_spec.AddField(article.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.WordCount(); ok {
		_spec.SetField(article.FieldWordCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedWordCount(); ok {
		_spec.AddField(article.FieldWordCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ReadingTime(); ok {
		_spec.SetField(article.FieldReadingTime, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedReadingTime(); ok {
		_spec.AddField(article.FieldReadingTime, field.TypeInt, value)
	}
	if value, ok := _u.mutation.IPLocation(); ok {
		_spec.SetField(article.FieldIPLocation, field.TypeString, value)
	}
	if _u.mutation.IPLocationCleared() {
		_spec.ClearField(article.FieldIPLocation, field.TypeString)
	}
	if value, ok := _u.mutation.PrimaryColor(); ok {
		_spec.SetField(article.FieldPrimaryColor, field.TypeString, value)
	}
	if _u.mutation.PrimaryColorCleared() {
		_spec.ClearField(article.FieldPrimaryColor, field.TypeString)
	}
	if value, ok := _u.mutation.IsPrimaryColorManual(); ok {
		_spec.SetField(article.FieldIsPrimaryColorManual, field.TypeBool, value)
	}
	if value, ok := _u.mutation.HomeSort(); ok {
		_spec.SetField(article.FieldHomeSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedHomeSort(); ok {
		_spec.AddField(article.FieldHomeSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.PinSort(); ok {
		_spec.SetField(article.FieldPinSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPinSort(); ok {
		_spec.AddField(article.FieldPinSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.TopImgURL(); ok {
		_spec.SetField(article.FieldTopImgURL, field.TypeString, value)
	}
	if _u.mutation.TopImgURLCleared() {
		_spec.ClearField(article.FieldTopImgURL, field.TypeString)
	}
	if value, ok := _u.mutation.Summaries(); ok {
		_spec.SetField(article.FieldSummaries, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedSummaries(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, article.FieldSummaries, value)
		})
	}
	if _u.mutation.SummariesCleared() {
		_spec.ClearField(article.FieldSummaries, field.TypeJSON)
	}
	if value, ok := _u.mutation.Abbrlink(); ok {
		_spec.SetField(article.FieldAbbrlink, field.TypeString, value)
	}
	if _u.mutation.AbbrlinkCleared() {
		_spec.ClearField(article.FieldAbbrlink, field.TypeString)
	}
	if value, ok := _u.mutation.Copyright(); ok {
		_spec.SetField(article.FieldCopyright, field.TypeBool, value)
	}
	if value, ok := _u.mutation.CopyrightAuthor(); ok {
		_spec.SetField(article.FieldCopyrightAuthor, field.TypeString, value)
	}
	if _u.mutation.CopyrightAuthorCleared() {
		_spec.ClearField(article.FieldCopyrightAuthor, field.TypeString)
	}
	if value, ok := _u.mutation.CopyrightAuthorHref(); ok {
		_spec.SetField(article.FieldCopyrightAuthorHref, field.TypeString, value)
	}
	if _u.mutation.CopyrightAuthorHrefCleared() {
		_spec.ClearField(article.FieldCopyrightAuthorHref, field.TypeString)
	}
	if value, ok := _u.mutation.CopyrightURL(); ok {
		_spec.SetField(article.FieldCopyrightURL, field.TypeString, value)
	}
	if _u.mutation.CopyrightURLCleared() {
		_spec.ClearField(article.FieldCopyrightURL, field.TypeString)
	}
	if _u.mutation.PostTagsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostTagsTable,
			Columns: article.PostTagsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(posttag.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPostTagsIDs(); len(nodes) > 0 && !_u.mutation.PostTagsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostTagsTable,
			Columns: article.PostTagsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(posttag.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.PostTagsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostTagsTable,
			Columns: article.PostTagsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(posttag.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.PostCategoriesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostCategoriesTable,
			Columns: article.PostCategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(postcategory.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPostCategoriesIDs(); len(nodes) > 0 && !_u.mutation.PostCategoriesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostCategoriesTable,
			Columns: article.PostCategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(postcategory.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.PostCategoriesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostCategoriesTable,
			Columns: article.PostCategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(postcategory.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.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   article.CommentsTable,
			Columns: []string{article.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !_u.mutation.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   article.CommentsTable,
			Columns: []string{article.CommentsColumn},
			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.CommentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   article.CommentsTable,
			Columns: []string{article.CommentsColumn},
			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{article.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

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

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

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

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

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

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

// SetNillableTitle sets the "title" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableTitle(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetTitle(*v)
	}
	return _u
}

// SetContentMd sets the "content_md" field.
func (_u *ArticleUpdateOne) SetContentMd(v string) *ArticleUpdateOne {
	_u.mutation.SetContentMd(v)
	return _u
}

// SetNillableContentMd sets the "content_md" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableContentMd(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetContentMd(*v)
	}
	return _u
}

// ClearContentMd clears the value of the "content_md" field.
func (_u *ArticleUpdateOne) ClearContentMd() *ArticleUpdateOne {
	_u.mutation.ClearContentMd()
	return _u
}

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

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

// ClearContentHTML clears the value of the "content_html" field.
func (_u *ArticleUpdateOne) ClearContentHTML() *ArticleUpdateOne {
	_u.mutation.ClearContentHTML()
	return _u
}

// SetCoverURL sets the "cover_url" field.
func (_u *ArticleUpdateOne) SetCoverURL(v string) *ArticleUpdateOne {
	_u.mutation.SetCoverURL(v)
	return _u
}

// SetNillableCoverURL sets the "cover_url" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableCoverURL(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetCoverURL(*v)
	}
	return _u
}

// ClearCoverURL clears the value of the "cover_url" field.
func (_u *ArticleUpdateOne) ClearCoverURL() *ArticleUpdateOne {
	_u.mutation.ClearCoverURL()
	return _u
}

// SetStatus sets the "status" field.
func (_u *ArticleUpdateOne) SetStatus(v article.Status) *ArticleUpdateOne {
	_u.mutation.SetStatus(v)
	return _u
}

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

// SetViewCount sets the "view_count" field.
func (_u *ArticleUpdateOne) SetViewCount(v int) *ArticleUpdateOne {
	_u.mutation.ResetViewCount()
	_u.mutation.SetViewCount(v)
	return _u
}

// SetNillableViewCount sets the "view_count" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableViewCount(v *int) *ArticleUpdateOne {
	if v != nil {
		_u.SetViewCount(*v)
	}
	return _u
}

// AddViewCount adds value to the "view_count" field.
func (_u *ArticleUpdateOne) AddViewCount(v int) *ArticleUpdateOne {
	_u.mutation.AddViewCount(v)
	return _u
}

// SetWordCount sets the "word_count" field.
func (_u *ArticleUpdateOne) SetWordCount(v int) *ArticleUpdateOne {
	_u.mutation.ResetWordCount()
	_u.mutation.SetWordCount(v)
	return _u
}

// SetNillableWordCount sets the "word_count" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableWordCount(v *int) *ArticleUpdateOne {
	if v != nil {
		_u.SetWordCount(*v)
	}
	return _u
}

// AddWordCount adds value to the "word_count" field.
func (_u *ArticleUpdateOne) AddWordCount(v int) *ArticleUpdateOne {
	_u.mutation.AddWordCount(v)
	return _u
}

// SetReadingTime sets the "reading_time" field.
func (_u *ArticleUpdateOne) SetReadingTime(v int) *ArticleUpdateOne {
	_u.mutation.ResetReadingTime()
	_u.mutation.SetReadingTime(v)
	return _u
}

// SetNillableReadingTime sets the "reading_time" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableReadingTime(v *int) *ArticleUpdateOne {
	if v != nil {
		_u.SetReadingTime(*v)
	}
	return _u
}

// AddReadingTime adds value to the "reading_time" field.
func (_u *ArticleUpdateOne) AddReadingTime(v int) *ArticleUpdateOne {
	_u.mutation.AddReadingTime(v)
	return _u
}

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

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

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

// SetPrimaryColor sets the "primary_color" field.
func (_u *ArticleUpdateOne) SetPrimaryColor(v string) *ArticleUpdateOne {
	_u.mutation.SetPrimaryColor(v)
	return _u
}

// SetNillablePrimaryColor sets the "primary_color" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillablePrimaryColor(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetPrimaryColor(*v)
	}
	return _u
}

// ClearPrimaryColor clears the value of the "primary_color" field.
func (_u *ArticleUpdateOne) ClearPrimaryColor() *ArticleUpdateOne {
	_u.mutation.ClearPrimaryColor()
	return _u
}

// SetIsPrimaryColorManual sets the "is_primary_color_manual" field.
func (_u *ArticleUpdateOne) SetIsPrimaryColorManual(v bool) *ArticleUpdateOne {
	_u.mutation.SetIsPrimaryColorManual(v)
	return _u
}

// SetNillableIsPrimaryColorManual sets the "is_primary_color_manual" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableIsPrimaryColorManual(v *bool) *ArticleUpdateOne {
	if v != nil {
		_u.SetIsPrimaryColorManual(*v)
	}
	return _u
}

// SetHomeSort sets the "home_sort" field.
func (_u *ArticleUpdateOne) SetHomeSort(v int) *ArticleUpdateOne {
	_u.mutation.ResetHomeSort()
	_u.mutation.SetHomeSort(v)
	return _u
}

// SetNillableHomeSort sets the "home_sort" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableHomeSort(v *int) *ArticleUpdateOne {
	if v != nil {
		_u.SetHomeSort(*v)
	}
	return _u
}

// AddHomeSort adds value to the "home_sort" field.
func (_u *ArticleUpdateOne) AddHomeSort(v int) *ArticleUpdateOne {
	_u.mutation.AddHomeSort(v)
	return _u
}

// SetPinSort sets the "pin_sort" field.
func (_u *ArticleUpdateOne) SetPinSort(v int) *ArticleUpdateOne {
	_u.mutation.ResetPinSort()
	_u.mutation.SetPinSort(v)
	return _u
}

// SetNillablePinSort sets the "pin_sort" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillablePinSort(v *int) *ArticleUpdateOne {
	if v != nil {
		_u.SetPinSort(*v)
	}
	return _u
}

// AddPinSort adds value to the "pin_sort" field.
func (_u *ArticleUpdateOne) AddPinSort(v int) *ArticleUpdateOne {
	_u.mutation.AddPinSort(v)
	return _u
}

// SetTopImgURL sets the "top_img_url" field.
func (_u *ArticleUpdateOne) SetTopImgURL(v string) *ArticleUpdateOne {
	_u.mutation.SetTopImgURL(v)
	return _u
}

// SetNillableTopImgURL sets the "top_img_url" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableTopImgURL(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetTopImgURL(*v)
	}
	return _u
}

// ClearTopImgURL clears the value of the "top_img_url" field.
func (_u *ArticleUpdateOne) ClearTopImgURL() *ArticleUpdateOne {
	_u.mutation.ClearTopImgURL()
	return _u
}

// SetSummaries sets the "summaries" field.
func (_u *ArticleUpdateOne) SetSummaries(v []string) *ArticleUpdateOne {
	_u.mutation.SetSummaries(v)
	return _u
}

// AppendSummaries appends value to the "summaries" field.
func (_u *ArticleUpdateOne) AppendSummaries(v []string) *ArticleUpdateOne {
	_u.mutation.AppendSummaries(v)
	return _u
}

// ClearSummaries clears the value of the "summaries" field.
func (_u *ArticleUpdateOne) ClearSummaries() *ArticleUpdateOne {
	_u.mutation.ClearSummaries()
	return _u
}

// SetAbbrlink sets the "abbrlink" field.
func (_u *ArticleUpdateOne) SetAbbrlink(v string) *ArticleUpdateOne {
	_u.mutation.SetAbbrlink(v)
	return _u
}

// SetNillableAbbrlink sets the "abbrlink" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableAbbrlink(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetAbbrlink(*v)
	}
	return _u
}

// ClearAbbrlink clears the value of the "abbrlink" field.
func (_u *ArticleUpdateOne) ClearAbbrlink() *ArticleUpdateOne {
	_u.mutation.ClearAbbrlink()
	return _u
}

// SetCopyright sets the "copyright" field.
func (_u *ArticleUpdateOne) SetCopyright(v bool) *ArticleUpdateOne {
	_u.mutation.SetCopyright(v)
	return _u
}

// SetNillableCopyright sets the "copyright" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableCopyright(v *bool) *ArticleUpdateOne {
	if v != nil {
		_u.SetCopyright(*v)
	}
	return _u
}

// SetCopyrightAuthor sets the "copyright_author" field.
func (_u *ArticleUpdateOne) SetCopyrightAuthor(v string) *ArticleUpdateOne {
	_u.mutation.SetCopyrightAuthor(v)
	return _u
}

// SetNillableCopyrightAuthor sets the "copyright_author" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableCopyrightAuthor(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetCopyrightAuthor(*v)
	}
	return _u
}

// ClearCopyrightAuthor clears the value of the "copyright_author" field.
func (_u *ArticleUpdateOne) ClearCopyrightAuthor() *ArticleUpdateOne {
	_u.mutation.ClearCopyrightAuthor()
	return _u
}

// SetCopyrightAuthorHref sets the "copyright_author_href" field.
func (_u *ArticleUpdateOne) SetCopyrightAuthorHref(v string) *ArticleUpdateOne {
	_u.mutation.SetCopyrightAuthorHref(v)
	return _u
}

// SetNillableCopyrightAuthorHref sets the "copyright_author_href" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableCopyrightAuthorHref(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetCopyrightAuthorHref(*v)
	}
	return _u
}

// ClearCopyrightAuthorHref clears the value of the "copyright_author_href" field.
func (_u *ArticleUpdateOne) ClearCopyrightAuthorHref() *ArticleUpdateOne {
	_u.mutation.ClearCopyrightAuthorHref()
	return _u
}

// SetCopyrightURL sets the "copyright_url" field.
func (_u *ArticleUpdateOne) SetCopyrightURL(v string) *ArticleUpdateOne {
	_u.mutation.SetCopyrightURL(v)
	return _u
}

// SetNillableCopyrightURL sets the "copyright_url" field if the given value is not nil.
func (_u *ArticleUpdateOne) SetNillableCopyrightURL(v *string) *ArticleUpdateOne {
	if v != nil {
		_u.SetCopyrightURL(*v)
	}
	return _u
}

// ClearCopyrightURL clears the value of the "copyright_url" field.
func (_u *ArticleUpdateOne) ClearCopyrightURL() *ArticleUpdateOne {
	_u.mutation.ClearCopyrightURL()
	return _u
}

// AddPostTagIDs adds the "post_tags" edge to the PostTag entity by IDs.
func (_u *ArticleUpdateOne) AddPostTagIDs(ids ...uint) *ArticleUpdateOne {
	_u.mutation.AddPostTagIDs(ids...)
	return _u
}

// AddPostTags adds the "post_tags" edges to the PostTag entity.
func (_u *ArticleUpdateOne) AddPostTags(v ...*PostTag) *ArticleUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPostTagIDs(ids...)
}

// AddPostCategoryIDs adds the "post_categories" edge to the PostCategory entity by IDs.
func (_u *ArticleUpdateOne) AddPostCategoryIDs(ids ...uint) *ArticleUpdateOne {
	_u.mutation.AddPostCategoryIDs(ids...)
	return _u
}

// AddPostCategories adds the "post_categories" edges to the PostCategory entity.
func (_u *ArticleUpdateOne) AddPostCategories(v ...*PostCategory) *ArticleUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPostCategoryIDs(ids...)
}

// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
func (_u *ArticleUpdateOne) AddCommentIDs(ids ...uint) *ArticleUpdateOne {
	_u.mutation.AddCommentIDs(ids...)
	return _u
}

// AddComments adds the "comments" edges to the Comment entity.
func (_u *ArticleUpdateOne) AddComments(v ...*Comment) *ArticleUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddCommentIDs(ids...)
}

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

// ClearPostTags clears all "post_tags" edges to the PostTag entity.
func (_u *ArticleUpdateOne) ClearPostTags() *ArticleUpdateOne {
	_u.mutation.ClearPostTags()
	return _u
}

// RemovePostTagIDs removes the "post_tags" edge to PostTag entities by IDs.
func (_u *ArticleUpdateOne) RemovePostTagIDs(ids ...uint) *ArticleUpdateOne {
	_u.mutation.RemovePostTagIDs(ids...)
	return _u
}

// RemovePostTags removes "post_tags" edges to PostTag entities.
func (_u *ArticleUpdateOne) RemovePostTags(v ...*PostTag) *ArticleUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePostTagIDs(ids...)
}

// ClearPostCategories clears all "post_categories" edges to the PostCategory entity.
func (_u *ArticleUpdateOne) ClearPostCategories() *ArticleUpdateOne {
	_u.mutation.ClearPostCategories()
	return _u
}

// RemovePostCategoryIDs removes the "post_categories" edge to PostCategory entities by IDs.
func (_u *ArticleUpdateOne) RemovePostCategoryIDs(ids ...uint) *ArticleUpdateOne {
	_u.mutation.RemovePostCategoryIDs(ids...)
	return _u
}

// RemovePostCategories removes "post_categories" edges to PostCategory entities.
func (_u *ArticleUpdateOne) RemovePostCategories(v ...*PostCategory) *ArticleUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePostCategoryIDs(ids...)
}

// ClearComments clears all "comments" edges to the Comment entity.
func (_u *ArticleUpdateOne) ClearComments() *ArticleUpdateOne {
	_u.mutation.ClearComments()
	return _u
}

// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
func (_u *ArticleUpdateOne) RemoveCommentIDs(ids ...uint) *ArticleUpdateOne {
	_u.mutation.RemoveCommentIDs(ids...)
	return _u
}

// RemoveComments removes "comments" edges to Comment entities.
func (_u *ArticleUpdateOne) RemoveComments(v ...*Comment) *ArticleUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveCommentIDs(ids...)
}

// Where appends a list predicates to the ArticleUpdate builder.
func (_u *ArticleUpdateOne) Where(ps ...predicate.Article) *ArticleUpdateOne {
	_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 *ArticleUpdateOne) Select(field string, fields ...string) *ArticleUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

// Save executes the query and returns the updated Article entity.
func (_u *ArticleUpdateOne) Save(ctx context.Context) (*Article, 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 *ArticleUpdateOne) SaveX(ctx context.Context) *Article {
	node, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *ArticleUpdateOne) 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 *ArticleUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if article.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized article.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := article.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *ArticleUpdateOne) check() error {
	if v, ok := _u.mutation.Title(); ok {
		if err := article.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Article.title": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := article.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Article.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ViewCount(); ok {
		if err := article.ViewCountValidator(v); err != nil {
			return &ValidationError{Name: "view_count", err: fmt.Errorf(`ent: validator failed for field "Article.view_count": %w`, err)}
		}
	}
	if v, ok := _u.mutation.WordCount(); ok {
		if err := article.WordCountValidator(v); err != nil {
			return &ValidationError{Name: "word_count", err: fmt.Errorf(`ent: validator failed for field "Article.word_count": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ReadingTime(); ok {
		if err := article.ReadingTimeValidator(v); err != nil {
			return &ValidationError{Name: "reading_time", err: fmt.Errorf(`ent: validator failed for field "Article.reading_time": %w`, err)}
		}
	}
	if v, ok := _u.mutation.HomeSort(); ok {
		if err := article.HomeSortValidator(v); err != nil {
			return &ValidationError{Name: "home_sort", err: fmt.Errorf(`ent: validator failed for field "Article.home_sort": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PinSort(); ok {
		if err := article.PinSortValidator(v); err != nil {
			return &ValidationError{Name: "pin_sort", err: fmt.Errorf(`ent: validator failed for field "Article.pin_sort": %w`, err)}
		}
	}
	return nil
}

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

func (_u *ArticleUpdateOne) sqlSave(ctx context.Context) (_node *Article, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(article.Table, article.Columns, sqlgraph.NewFieldSpec(article.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Article.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, article.FieldID)
		for _, f := range fields {
			if !article.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != article.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(article.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(article.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(article.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Title(); ok {
		_spec.SetField(article.FieldTitle, field.TypeString, value)
	}
	if value, ok := _u.mutation.ContentMd(); ok {
		_spec.SetField(article.FieldContentMd, field.TypeString, value)
	}
	if _u.mutation.ContentMdCleared() {
		_spec.ClearField(article.FieldContentMd, field.TypeString)
	}
	if value, ok := _u.mutation.ContentHTML(); ok {
		_spec.SetField(article.FieldContentHTML, field.TypeString, value)
	}
	if _u.mutation.ContentHTMLCleared() {
		_spec.ClearField(article.FieldContentHTML, field.TypeString)
	}
	if value, ok := _u.mutation.CoverURL(); ok {
		_spec.SetField(article.FieldCoverURL, field.TypeString, value)
	}
	if _u.mutation.CoverURLCleared() {
		_spec.ClearField(article.FieldCoverURL, field.TypeString)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(article.FieldStatus, field.TypeEnum, value)
	}
	if value, ok := _u.mutation.ViewCount(); ok {
		_spec.SetField(article.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedViewCount(); ok {
		_spec.AddField(article.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.WordCount(); ok {
		_spec.SetField(article.FieldWordCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedWordCount(); ok {
		_spec.AddField(article.FieldWordCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ReadingTime(); ok {
		_spec.SetField(article.FieldReadingTime, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedReadingTime(); ok {
		_spec.AddField(article.FieldReadingTime, field.TypeInt, value)
	}
	if value, ok := _u.mutation.IPLocation(); ok {
		_spec.SetField(article.FieldIPLocation, field.TypeString, value)
	}
	if _u.mutation.IPLocationCleared() {
		_spec.ClearField(article.FieldIPLocation, field.TypeString)
	}
	if value, ok := _u.mutation.PrimaryColor(); ok {
		_spec.SetField(article.FieldPrimaryColor, field.TypeString, value)
	}
	if _u.mutation.PrimaryColorCleared() {
		_spec.ClearField(article.FieldPrimaryColor, field.TypeString)
	}
	if value, ok := _u.mutation.IsPrimaryColorManual(); ok {
		_spec.SetField(article.FieldIsPrimaryColorManual, field.TypeBool, value)
	}
	if value, ok := _u.mutation.HomeSort(); ok {
		_spec.SetField(article.FieldHomeSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedHomeSort(); ok {
		_spec.AddField(article.FieldHomeSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.PinSort(); ok {
		_spec.SetField(article.FieldPinSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPinSort(); ok {
		_spec.AddField(article.FieldPinSort, field.TypeInt, value)
	}
	if value, ok := _u.mutation.TopImgURL(); ok {
		_spec.SetField(article.FieldTopImgURL, field.TypeString, value)
	}
	if _u.mutation.TopImgURLCleared() {
		_spec.ClearField(article.FieldTopImgURL, field.TypeString)
	}
	if value, ok := _u.mutation.Summaries(); ok {
		_spec.SetField(article.FieldSummaries, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedSummaries(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, article.FieldSummaries, value)
		})
	}
	if _u.mutation.SummariesCleared() {
		_spec.ClearField(article.FieldSummaries, field.TypeJSON)
	}
	if value, ok := _u.mutation.Abbrlink(); ok {
		_spec.SetField(article.FieldAbbrlink, field.TypeString, value)
	}
	if _u.mutation.AbbrlinkCleared() {
		_spec.ClearField(article.FieldAbbrlink, field.TypeString)
	}
	if value, ok := _u.mutation.Copyright(); ok {
		_spec.SetField(article.FieldCopyright, field.TypeBool, value)
	}
	if value, ok := _u.mutation.CopyrightAuthor(); ok {
		_spec.SetField(article.FieldCopyrightAuthor, field.TypeString, value)
	}
	if _u.mutation.CopyrightAuthorCleared() {
		_spec.ClearField(article.FieldCopyrightAuthor, field.TypeString)
	}
	if value, ok := _u.mutation.CopyrightAuthorHref(); ok {
		_spec.SetField(article.FieldCopyrightAuthorHref, field.TypeString, value)
	}
	if _u.mutation.CopyrightAuthorHrefCleared() {
		_spec.ClearField(article.FieldCopyrightAuthorHref, field.TypeString)
	}
	if value, ok := _u.mutation.CopyrightURL(); ok {
		_spec.SetField(article.FieldCopyrightURL, field.TypeString, value)
	}
	if _u.mutation.CopyrightURLCleared() {
		_spec.ClearField(article.FieldCopyrightURL, field.TypeString)
	}
	if _u.mutation.PostTagsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostTagsTable,
			Columns: article.PostTagsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(posttag.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPostTagsIDs(); len(nodes) > 0 && !_u.mutation.PostTagsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostTagsTable,
			Columns: article.PostTagsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(posttag.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.PostTagsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostTagsTable,
			Columns: article.PostTagsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(posttag.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.PostCategoriesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostCategoriesTable,
			Columns: article.PostCategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(postcategory.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPostCategoriesIDs(); len(nodes) > 0 && !_u.mutation.PostCategoriesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostCategoriesTable,
			Columns: article.PostCategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(postcategory.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.PostCategoriesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   article.PostCategoriesTable,
			Columns: article.PostCategoriesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(postcategory.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.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   article.CommentsTable,
			Columns: []string{article.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !_u.mutation.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   article.CommentsTable,
			Columns: []string{article.CommentsColumn},
			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.CommentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   article.CommentsTable,
			Columns: []string{article.CommentsColumn},
			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 = &Article{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{article.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
