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

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

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

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

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

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

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

// SetImageURL sets the "image_url" field.
func (_u *AlbumUpdate) SetImageURL(v string) *AlbumUpdate {
	_u.mutation.SetImageURL(v)
	return _u
}

// SetNillableImageURL sets the "image_url" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableImageURL(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetImageURL(*v)
	}
	return _u
}

// SetBigImageURL sets the "big_image_url" field.
func (_u *AlbumUpdate) SetBigImageURL(v string) *AlbumUpdate {
	_u.mutation.SetBigImageURL(v)
	return _u
}

// SetNillableBigImageURL sets the "big_image_url" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableBigImageURL(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetBigImageURL(*v)
	}
	return _u
}

// ClearBigImageURL clears the value of the "big_image_url" field.
func (_u *AlbumUpdate) ClearBigImageURL() *AlbumUpdate {
	_u.mutation.ClearBigImageURL()
	return _u
}

// SetDownloadURL sets the "download_url" field.
func (_u *AlbumUpdate) SetDownloadURL(v string) *AlbumUpdate {
	_u.mutation.SetDownloadURL(v)
	return _u
}

// SetNillableDownloadURL sets the "download_url" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableDownloadURL(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetDownloadURL(*v)
	}
	return _u
}

// ClearDownloadURL clears the value of the "download_url" field.
func (_u *AlbumUpdate) ClearDownloadURL() *AlbumUpdate {
	_u.mutation.ClearDownloadURL()
	return _u
}

// SetThumbParam sets the "thumb_param" field.
func (_u *AlbumUpdate) SetThumbParam(v string) *AlbumUpdate {
	_u.mutation.SetThumbParam(v)
	return _u
}

// SetNillableThumbParam sets the "thumb_param" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableThumbParam(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetThumbParam(*v)
	}
	return _u
}

// ClearThumbParam clears the value of the "thumb_param" field.
func (_u *AlbumUpdate) ClearThumbParam() *AlbumUpdate {
	_u.mutation.ClearThumbParam()
	return _u
}

// SetBigParam sets the "big_param" field.
func (_u *AlbumUpdate) SetBigParam(v string) *AlbumUpdate {
	_u.mutation.SetBigParam(v)
	return _u
}

// SetNillableBigParam sets the "big_param" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableBigParam(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetBigParam(*v)
	}
	return _u
}

// ClearBigParam clears the value of the "big_param" field.
func (_u *AlbumUpdate) ClearBigParam() *AlbumUpdate {
	_u.mutation.ClearBigParam()
	return _u
}

// SetTags sets the "tags" field.
func (_u *AlbumUpdate) SetTags(v string) *AlbumUpdate {
	_u.mutation.SetTags(v)
	return _u
}

// SetNillableTags sets the "tags" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableTags(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetTags(*v)
	}
	return _u
}

// ClearTags clears the value of the "tags" field.
func (_u *AlbumUpdate) ClearTags() *AlbumUpdate {
	_u.mutation.ClearTags()
	return _u
}

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

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

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

// SetDownloadCount sets the "download_count" field.
func (_u *AlbumUpdate) SetDownloadCount(v int) *AlbumUpdate {
	_u.mutation.ResetDownloadCount()
	_u.mutation.SetDownloadCount(v)
	return _u
}

// SetNillableDownloadCount sets the "download_count" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableDownloadCount(v *int) *AlbumUpdate {
	if v != nil {
		_u.SetDownloadCount(*v)
	}
	return _u
}

// AddDownloadCount adds value to the "download_count" field.
func (_u *AlbumUpdate) AddDownloadCount(v int) *AlbumUpdate {
	_u.mutation.AddDownloadCount(v)
	return _u
}

// SetWidth sets the "width" field.
func (_u *AlbumUpdate) SetWidth(v int) *AlbumUpdate {
	_u.mutation.ResetWidth()
	_u.mutation.SetWidth(v)
	return _u
}

// SetNillableWidth sets the "width" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableWidth(v *int) *AlbumUpdate {
	if v != nil {
		_u.SetWidth(*v)
	}
	return _u
}

// AddWidth adds value to the "width" field.
func (_u *AlbumUpdate) AddWidth(v int) *AlbumUpdate {
	_u.mutation.AddWidth(v)
	return _u
}

// ClearWidth clears the value of the "width" field.
func (_u *AlbumUpdate) ClearWidth() *AlbumUpdate {
	_u.mutation.ClearWidth()
	return _u
}

// SetHeight sets the "height" field.
func (_u *AlbumUpdate) SetHeight(v int) *AlbumUpdate {
	_u.mutation.ResetHeight()
	_u.mutation.SetHeight(v)
	return _u
}

// SetNillableHeight sets the "height" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableHeight(v *int) *AlbumUpdate {
	if v != nil {
		_u.SetHeight(*v)
	}
	return _u
}

// AddHeight adds value to the "height" field.
func (_u *AlbumUpdate) AddHeight(v int) *AlbumUpdate {
	_u.mutation.AddHeight(v)
	return _u
}

// ClearHeight clears the value of the "height" field.
func (_u *AlbumUpdate) ClearHeight() *AlbumUpdate {
	_u.mutation.ClearHeight()
	return _u
}

// SetFileSize sets the "file_size" field.
func (_u *AlbumUpdate) SetFileSize(v int64) *AlbumUpdate {
	_u.mutation.ResetFileSize()
	_u.mutation.SetFileSize(v)
	return _u
}

// SetNillableFileSize sets the "file_size" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableFileSize(v *int64) *AlbumUpdate {
	if v != nil {
		_u.SetFileSize(*v)
	}
	return _u
}

// AddFileSize adds value to the "file_size" field.
func (_u *AlbumUpdate) AddFileSize(v int64) *AlbumUpdate {
	_u.mutation.AddFileSize(v)
	return _u
}

// ClearFileSize clears the value of the "file_size" field.
func (_u *AlbumUpdate) ClearFileSize() *AlbumUpdate {
	_u.mutation.ClearFileSize()
	return _u
}

// SetFormat sets the "format" field.
func (_u *AlbumUpdate) SetFormat(v string) *AlbumUpdate {
	_u.mutation.SetFormat(v)
	return _u
}

// SetNillableFormat sets the "format" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableFormat(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetFormat(*v)
	}
	return _u
}

// ClearFormat clears the value of the "format" field.
func (_u *AlbumUpdate) ClearFormat() *AlbumUpdate {
	_u.mutation.ClearFormat()
	return _u
}

// SetAspectRatio sets the "aspect_ratio" field.
func (_u *AlbumUpdate) SetAspectRatio(v string) *AlbumUpdate {
	_u.mutation.SetAspectRatio(v)
	return _u
}

// SetNillableAspectRatio sets the "aspect_ratio" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableAspectRatio(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetAspectRatio(*v)
	}
	return _u
}

// ClearAspectRatio clears the value of the "aspect_ratio" field.
func (_u *AlbumUpdate) ClearAspectRatio() *AlbumUpdate {
	_u.mutation.ClearAspectRatio()
	return _u
}

// SetFileHash sets the "file_hash" field.
func (_u *AlbumUpdate) SetFileHash(v string) *AlbumUpdate {
	_u.mutation.SetFileHash(v)
	return _u
}

// SetNillableFileHash sets the "file_hash" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableFileHash(v *string) *AlbumUpdate {
	if v != nil {
		_u.SetFileHash(*v)
	}
	return _u
}

// SetDisplayOrder sets the "display_order" field.
func (_u *AlbumUpdate) SetDisplayOrder(v int) *AlbumUpdate {
	_u.mutation.ResetDisplayOrder()
	_u.mutation.SetDisplayOrder(v)
	return _u
}

// SetNillableDisplayOrder sets the "display_order" field if the given value is not nil.
func (_u *AlbumUpdate) SetNillableDisplayOrder(v *int) *AlbumUpdate {
	if v != nil {
		_u.SetDisplayOrder(*v)
	}
	return _u
}

// AddDisplayOrder adds value to the "display_order" field.
func (_u *AlbumUpdate) AddDisplayOrder(v int) *AlbumUpdate {
	_u.mutation.AddDisplayOrder(v)
	return _u
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *AlbumUpdate) check() error {
	if v, ok := _u.mutation.ImageURL(); ok {
		if err := album.ImageURLValidator(v); err != nil {
			return &ValidationError{Name: "image_url", err: fmt.Errorf(`ent: validator failed for field "Album.image_url": %w`, err)}
		}
	}
	if v, ok := _u.mutation.BigImageURL(); ok {
		if err := album.BigImageURLValidator(v); err != nil {
			return &ValidationError{Name: "big_image_url", err: fmt.Errorf(`ent: validator failed for field "Album.big_image_url": %w`, err)}
		}
	}
	if v, ok := _u.mutation.DownloadURL(); ok {
		if err := album.DownloadURLValidator(v); err != nil {
			return &ValidationError{Name: "download_url", err: fmt.Errorf(`ent: validator failed for field "Album.download_url": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ThumbParam(); ok {
		if err := album.ThumbParamValidator(v); err != nil {
			return &ValidationError{Name: "thumb_param", err: fmt.Errorf(`ent: validator failed for field "Album.thumb_param": %w`, err)}
		}
	}
	if v, ok := _u.mutation.BigParam(); ok {
		if err := album.BigParamValidator(v); err != nil {
			return &ValidationError{Name: "big_param", err: fmt.Errorf(`ent: validator failed for field "Album.big_param": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Tags(); ok {
		if err := album.TagsValidator(v); err != nil {
			return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Album.tags": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Format(); ok {
		if err := album.FormatValidator(v); err != nil {
			return &ValidationError{Name: "format", err: fmt.Errorf(`ent: validator failed for field "Album.format": %w`, err)}
		}
	}
	if v, ok := _u.mutation.AspectRatio(); ok {
		if err := album.AspectRatioValidator(v); err != nil {
			return &ValidationError{Name: "aspect_ratio", err: fmt.Errorf(`ent: validator failed for field "Album.aspect_ratio": %w`, err)}
		}
	}
	if v, ok := _u.mutation.FileHash(); ok {
		if err := album.FileHashValidator(v); err != nil {
			return &ValidationError{Name: "file_hash", err: fmt.Errorf(`ent: validator failed for field "Album.file_hash": %w`, err)}
		}
	}
	return nil
}

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

func (_u *AlbumUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(album.Table, album.Columns, sqlgraph.NewFieldSpec(album.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(album.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(album.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(album.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.ImageURL(); ok {
		_spec.SetField(album.FieldImageURL, field.TypeString, value)
	}
	if value, ok := _u.mutation.BigImageURL(); ok {
		_spec.SetField(album.FieldBigImageURL, field.TypeString, value)
	}
	if _u.mutation.BigImageURLCleared() {
		_spec.ClearField(album.FieldBigImageURL, field.TypeString)
	}
	if value, ok := _u.mutation.DownloadURL(); ok {
		_spec.SetField(album.FieldDownloadURL, field.TypeString, value)
	}
	if _u.mutation.DownloadURLCleared() {
		_spec.ClearField(album.FieldDownloadURL, field.TypeString)
	}
	if value, ok := _u.mutation.ThumbParam(); ok {
		_spec.SetField(album.FieldThumbParam, field.TypeString, value)
	}
	if _u.mutation.ThumbParamCleared() {
		_spec.ClearField(album.FieldThumbParam, field.TypeString)
	}
	if value, ok := _u.mutation.BigParam(); ok {
		_spec.SetField(album.FieldBigParam, field.TypeString, value)
	}
	if _u.mutation.BigParamCleared() {
		_spec.ClearField(album.FieldBigParam, field.TypeString)
	}
	if value, ok := _u.mutation.Tags(); ok {
		_spec.SetField(album.FieldTags, field.TypeString, value)
	}
	if _u.mutation.TagsCleared() {
		_spec.ClearField(album.FieldTags, field.TypeString)
	}
	if value, ok := _u.mutation.ViewCount(); ok {
		_spec.SetField(album.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedViewCount(); ok {
		_spec.AddField(album.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.DownloadCount(); ok {
		_spec.SetField(album.FieldDownloadCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDownloadCount(); ok {
		_spec.AddField(album.FieldDownloadCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Width(); ok {
		_spec.SetField(album.FieldWidth, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedWidth(); ok {
		_spec.AddField(album.FieldWidth, field.TypeInt, value)
	}
	if _u.mutation.WidthCleared() {
		_spec.ClearField(album.FieldWidth, field.TypeInt)
	}
	if value, ok := _u.mutation.Height(); ok {
		_spec.SetField(album.FieldHeight, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedHeight(); ok {
		_spec.AddField(album.FieldHeight, field.TypeInt, value)
	}
	if _u.mutation.HeightCleared() {
		_spec.ClearField(album.FieldHeight, field.TypeInt)
	}
	if value, ok := _u.mutation.FileSize(); ok {
		_spec.SetField(album.FieldFileSize, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedFileSize(); ok {
		_spec.AddField(album.FieldFileSize, field.TypeInt64, value)
	}
	if _u.mutation.FileSizeCleared() {
		_spec.ClearField(album.FieldFileSize, field.TypeInt64)
	}
	if value, ok := _u.mutation.Format(); ok {
		_spec.SetField(album.FieldFormat, field.TypeString, value)
	}
	if _u.mutation.FormatCleared() {
		_spec.ClearField(album.FieldFormat, field.TypeString)
	}
	if value, ok := _u.mutation.AspectRatio(); ok {
		_spec.SetField(album.FieldAspectRatio, field.TypeString, value)
	}
	if _u.mutation.AspectRatioCleared() {
		_spec.ClearField(album.FieldAspectRatio, field.TypeString)
	}
	if value, ok := _u.mutation.FileHash(); ok {
		_spec.SetField(album.FieldFileHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.DisplayOrder(); ok {
		_spec.SetField(album.FieldDisplayOrder, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDisplayOrder(); ok {
		_spec.AddField(album.FieldDisplayOrder, field.TypeInt, value)
	}
	_spec.AddModifiers(_u.modifiers...)
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{album.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

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

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

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

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

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

// SetImageURL sets the "image_url" field.
func (_u *AlbumUpdateOne) SetImageURL(v string) *AlbumUpdateOne {
	_u.mutation.SetImageURL(v)
	return _u
}

// SetNillableImageURL sets the "image_url" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableImageURL(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetImageURL(*v)
	}
	return _u
}

// SetBigImageURL sets the "big_image_url" field.
func (_u *AlbumUpdateOne) SetBigImageURL(v string) *AlbumUpdateOne {
	_u.mutation.SetBigImageURL(v)
	return _u
}

// SetNillableBigImageURL sets the "big_image_url" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableBigImageURL(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetBigImageURL(*v)
	}
	return _u
}

// ClearBigImageURL clears the value of the "big_image_url" field.
func (_u *AlbumUpdateOne) ClearBigImageURL() *AlbumUpdateOne {
	_u.mutation.ClearBigImageURL()
	return _u
}

// SetDownloadURL sets the "download_url" field.
func (_u *AlbumUpdateOne) SetDownloadURL(v string) *AlbumUpdateOne {
	_u.mutation.SetDownloadURL(v)
	return _u
}

// SetNillableDownloadURL sets the "download_url" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableDownloadURL(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetDownloadURL(*v)
	}
	return _u
}

// ClearDownloadURL clears the value of the "download_url" field.
func (_u *AlbumUpdateOne) ClearDownloadURL() *AlbumUpdateOne {
	_u.mutation.ClearDownloadURL()
	return _u
}

// SetThumbParam sets the "thumb_param" field.
func (_u *AlbumUpdateOne) SetThumbParam(v string) *AlbumUpdateOne {
	_u.mutation.SetThumbParam(v)
	return _u
}

// SetNillableThumbParam sets the "thumb_param" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableThumbParam(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetThumbParam(*v)
	}
	return _u
}

// ClearThumbParam clears the value of the "thumb_param" field.
func (_u *AlbumUpdateOne) ClearThumbParam() *AlbumUpdateOne {
	_u.mutation.ClearThumbParam()
	return _u
}

// SetBigParam sets the "big_param" field.
func (_u *AlbumUpdateOne) SetBigParam(v string) *AlbumUpdateOne {
	_u.mutation.SetBigParam(v)
	return _u
}

// SetNillableBigParam sets the "big_param" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableBigParam(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetBigParam(*v)
	}
	return _u
}

// ClearBigParam clears the value of the "big_param" field.
func (_u *AlbumUpdateOne) ClearBigParam() *AlbumUpdateOne {
	_u.mutation.ClearBigParam()
	return _u
}

// SetTags sets the "tags" field.
func (_u *AlbumUpdateOne) SetTags(v string) *AlbumUpdateOne {
	_u.mutation.SetTags(v)
	return _u
}

// SetNillableTags sets the "tags" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableTags(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetTags(*v)
	}
	return _u
}

// ClearTags clears the value of the "tags" field.
func (_u *AlbumUpdateOne) ClearTags() *AlbumUpdateOne {
	_u.mutation.ClearTags()
	return _u
}

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

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

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

// SetDownloadCount sets the "download_count" field.
func (_u *AlbumUpdateOne) SetDownloadCount(v int) *AlbumUpdateOne {
	_u.mutation.ResetDownloadCount()
	_u.mutation.SetDownloadCount(v)
	return _u
}

// SetNillableDownloadCount sets the "download_count" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableDownloadCount(v *int) *AlbumUpdateOne {
	if v != nil {
		_u.SetDownloadCount(*v)
	}
	return _u
}

// AddDownloadCount adds value to the "download_count" field.
func (_u *AlbumUpdateOne) AddDownloadCount(v int) *AlbumUpdateOne {
	_u.mutation.AddDownloadCount(v)
	return _u
}

// SetWidth sets the "width" field.
func (_u *AlbumUpdateOne) SetWidth(v int) *AlbumUpdateOne {
	_u.mutation.ResetWidth()
	_u.mutation.SetWidth(v)
	return _u
}

// SetNillableWidth sets the "width" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableWidth(v *int) *AlbumUpdateOne {
	if v != nil {
		_u.SetWidth(*v)
	}
	return _u
}

// AddWidth adds value to the "width" field.
func (_u *AlbumUpdateOne) AddWidth(v int) *AlbumUpdateOne {
	_u.mutation.AddWidth(v)
	return _u
}

// ClearWidth clears the value of the "width" field.
func (_u *AlbumUpdateOne) ClearWidth() *AlbumUpdateOne {
	_u.mutation.ClearWidth()
	return _u
}

// SetHeight sets the "height" field.
func (_u *AlbumUpdateOne) SetHeight(v int) *AlbumUpdateOne {
	_u.mutation.ResetHeight()
	_u.mutation.SetHeight(v)
	return _u
}

// SetNillableHeight sets the "height" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableHeight(v *int) *AlbumUpdateOne {
	if v != nil {
		_u.SetHeight(*v)
	}
	return _u
}

// AddHeight adds value to the "height" field.
func (_u *AlbumUpdateOne) AddHeight(v int) *AlbumUpdateOne {
	_u.mutation.AddHeight(v)
	return _u
}

// ClearHeight clears the value of the "height" field.
func (_u *AlbumUpdateOne) ClearHeight() *AlbumUpdateOne {
	_u.mutation.ClearHeight()
	return _u
}

// SetFileSize sets the "file_size" field.
func (_u *AlbumUpdateOne) SetFileSize(v int64) *AlbumUpdateOne {
	_u.mutation.ResetFileSize()
	_u.mutation.SetFileSize(v)
	return _u
}

// SetNillableFileSize sets the "file_size" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableFileSize(v *int64) *AlbumUpdateOne {
	if v != nil {
		_u.SetFileSize(*v)
	}
	return _u
}

// AddFileSize adds value to the "file_size" field.
func (_u *AlbumUpdateOne) AddFileSize(v int64) *AlbumUpdateOne {
	_u.mutation.AddFileSize(v)
	return _u
}

// ClearFileSize clears the value of the "file_size" field.
func (_u *AlbumUpdateOne) ClearFileSize() *AlbumUpdateOne {
	_u.mutation.ClearFileSize()
	return _u
}

// SetFormat sets the "format" field.
func (_u *AlbumUpdateOne) SetFormat(v string) *AlbumUpdateOne {
	_u.mutation.SetFormat(v)
	return _u
}

// SetNillableFormat sets the "format" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableFormat(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetFormat(*v)
	}
	return _u
}

// ClearFormat clears the value of the "format" field.
func (_u *AlbumUpdateOne) ClearFormat() *AlbumUpdateOne {
	_u.mutation.ClearFormat()
	return _u
}

// SetAspectRatio sets the "aspect_ratio" field.
func (_u *AlbumUpdateOne) SetAspectRatio(v string) *AlbumUpdateOne {
	_u.mutation.SetAspectRatio(v)
	return _u
}

// SetNillableAspectRatio sets the "aspect_ratio" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableAspectRatio(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetAspectRatio(*v)
	}
	return _u
}

// ClearAspectRatio clears the value of the "aspect_ratio" field.
func (_u *AlbumUpdateOne) ClearAspectRatio() *AlbumUpdateOne {
	_u.mutation.ClearAspectRatio()
	return _u
}

// SetFileHash sets the "file_hash" field.
func (_u *AlbumUpdateOne) SetFileHash(v string) *AlbumUpdateOne {
	_u.mutation.SetFileHash(v)
	return _u
}

// SetNillableFileHash sets the "file_hash" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableFileHash(v *string) *AlbumUpdateOne {
	if v != nil {
		_u.SetFileHash(*v)
	}
	return _u
}

// SetDisplayOrder sets the "display_order" field.
func (_u *AlbumUpdateOne) SetDisplayOrder(v int) *AlbumUpdateOne {
	_u.mutation.ResetDisplayOrder()
	_u.mutation.SetDisplayOrder(v)
	return _u
}

// SetNillableDisplayOrder sets the "display_order" field if the given value is not nil.
func (_u *AlbumUpdateOne) SetNillableDisplayOrder(v *int) *AlbumUpdateOne {
	if v != nil {
		_u.SetDisplayOrder(*v)
	}
	return _u
}

// AddDisplayOrder adds value to the "display_order" field.
func (_u *AlbumUpdateOne) AddDisplayOrder(v int) *AlbumUpdateOne {
	_u.mutation.AddDisplayOrder(v)
	return _u
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *AlbumUpdateOne) check() error {
	if v, ok := _u.mutation.ImageURL(); ok {
		if err := album.ImageURLValidator(v); err != nil {
			return &ValidationError{Name: "image_url", err: fmt.Errorf(`ent: validator failed for field "Album.image_url": %w`, err)}
		}
	}
	if v, ok := _u.mutation.BigImageURL(); ok {
		if err := album.BigImageURLValidator(v); err != nil {
			return &ValidationError{Name: "big_image_url", err: fmt.Errorf(`ent: validator failed for field "Album.big_image_url": %w`, err)}
		}
	}
	if v, ok := _u.mutation.DownloadURL(); ok {
		if err := album.DownloadURLValidator(v); err != nil {
			return &ValidationError{Name: "download_url", err: fmt.Errorf(`ent: validator failed for field "Album.download_url": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ThumbParam(); ok {
		if err := album.ThumbParamValidator(v); err != nil {
			return &ValidationError{Name: "thumb_param", err: fmt.Errorf(`ent: validator failed for field "Album.thumb_param": %w`, err)}
		}
	}
	if v, ok := _u.mutation.BigParam(); ok {
		if err := album.BigParamValidator(v); err != nil {
			return &ValidationError{Name: "big_param", err: fmt.Errorf(`ent: validator failed for field "Album.big_param": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Tags(); ok {
		if err := album.TagsValidator(v); err != nil {
			return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Album.tags": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Format(); ok {
		if err := album.FormatValidator(v); err != nil {
			return &ValidationError{Name: "format", err: fmt.Errorf(`ent: validator failed for field "Album.format": %w`, err)}
		}
	}
	if v, ok := _u.mutation.AspectRatio(); ok {
		if err := album.AspectRatioValidator(v); err != nil {
			return &ValidationError{Name: "aspect_ratio", err: fmt.Errorf(`ent: validator failed for field "Album.aspect_ratio": %w`, err)}
		}
	}
	if v, ok := _u.mutation.FileHash(); ok {
		if err := album.FileHashValidator(v); err != nil {
			return &ValidationError{Name: "file_hash", err: fmt.Errorf(`ent: validator failed for field "Album.file_hash": %w`, err)}
		}
	}
	return nil
}

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

func (_u *AlbumUpdateOne) sqlSave(ctx context.Context) (_node *Album, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(album.Table, album.Columns, sqlgraph.NewFieldSpec(album.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Album.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, album.FieldID)
		for _, f := range fields {
			if !album.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != album.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(album.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(album.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(album.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.ImageURL(); ok {
		_spec.SetField(album.FieldImageURL, field.TypeString, value)
	}
	if value, ok := _u.mutation.BigImageURL(); ok {
		_spec.SetField(album.FieldBigImageURL, field.TypeString, value)
	}
	if _u.mutation.BigImageURLCleared() {
		_spec.ClearField(album.FieldBigImageURL, field.TypeString)
	}
	if value, ok := _u.mutation.DownloadURL(); ok {
		_spec.SetField(album.FieldDownloadURL, field.TypeString, value)
	}
	if _u.mutation.DownloadURLCleared() {
		_spec.ClearField(album.FieldDownloadURL, field.TypeString)
	}
	if value, ok := _u.mutation.ThumbParam(); ok {
		_spec.SetField(album.FieldThumbParam, field.TypeString, value)
	}
	if _u.mutation.ThumbParamCleared() {
		_spec.ClearField(album.FieldThumbParam, field.TypeString)
	}
	if value, ok := _u.mutation.BigParam(); ok {
		_spec.SetField(album.FieldBigParam, field.TypeString, value)
	}
	if _u.mutation.BigParamCleared() {
		_spec.ClearField(album.FieldBigParam, field.TypeString)
	}
	if value, ok := _u.mutation.Tags(); ok {
		_spec.SetField(album.FieldTags, field.TypeString, value)
	}
	if _u.mutation.TagsCleared() {
		_spec.ClearField(album.FieldTags, field.TypeString)
	}
	if value, ok := _u.mutation.ViewCount(); ok {
		_spec.SetField(album.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedViewCount(); ok {
		_spec.AddField(album.FieldViewCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.DownloadCount(); ok {
		_spec.SetField(album.FieldDownloadCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDownloadCount(); ok {
		_spec.AddField(album.FieldDownloadCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Width(); ok {
		_spec.SetField(album.FieldWidth, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedWidth(); ok {
		_spec.AddField(album.FieldWidth, field.TypeInt, value)
	}
	if _u.mutation.WidthCleared() {
		_spec.ClearField(album.FieldWidth, field.TypeInt)
	}
	if value, ok := _u.mutation.Height(); ok {
		_spec.SetField(album.FieldHeight, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedHeight(); ok {
		_spec.AddField(album.FieldHeight, field.TypeInt, value)
	}
	if _u.mutation.HeightCleared() {
		_spec.ClearField(album.FieldHeight, field.TypeInt)
	}
	if value, ok := _u.mutation.FileSize(); ok {
		_spec.SetField(album.FieldFileSize, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedFileSize(); ok {
		_spec.AddField(album.FieldFileSize, field.TypeInt64, value)
	}
	if _u.mutation.FileSizeCleared() {
		_spec.ClearField(album.FieldFileSize, field.TypeInt64)
	}
	if value, ok := _u.mutation.Format(); ok {
		_spec.SetField(album.FieldFormat, field.TypeString, value)
	}
	if _u.mutation.FormatCleared() {
		_spec.ClearField(album.FieldFormat, field.TypeString)
	}
	if value, ok := _u.mutation.AspectRatio(); ok {
		_spec.SetField(album.FieldAspectRatio, field.TypeString, value)
	}
	if _u.mutation.AspectRatioCleared() {
		_spec.ClearField(album.FieldAspectRatio, field.TypeString)
	}
	if value, ok := _u.mutation.FileHash(); ok {
		_spec.SetField(album.FieldFileHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.DisplayOrder(); ok {
		_spec.SetField(album.FieldDisplayOrder, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDisplayOrder(); ok {
		_spec.AddField(album.FieldDisplayOrder, field.TypeInt, value)
	}
	_spec.AddModifiers(_u.modifiers...)
	_node = &Album{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{album.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
