// 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/Wei-Shaw/sub2api/ent/batchimageitem"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
)

// BatchImageItemUpdate is the builder for updating BatchImageItem entities.
type BatchImageItemUpdate struct {
	config
	hooks    []Hook
	mutation *BatchImageItemMutation
}

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

// SetJobID sets the "job_id" field.
func (_u *BatchImageItemUpdate) SetJobID(v string) *BatchImageItemUpdate {
	_u.mutation.SetJobID(v)
	return _u
}

// SetNillableJobID sets the "job_id" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableJobID(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetJobID(*v)
	}
	return _u
}

// SetCustomID sets the "custom_id" field.
func (_u *BatchImageItemUpdate) SetCustomID(v string) *BatchImageItemUpdate {
	_u.mutation.SetCustomID(v)
	return _u
}

// SetNillableCustomID sets the "custom_id" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableCustomID(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetCustomID(*v)
	}
	return _u
}

// SetStatus sets the "status" field.
func (_u *BatchImageItemUpdate) SetStatus(v string) *BatchImageItemUpdate {
	_u.mutation.SetStatus(v)
	return _u
}

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

// SetRequestHash sets the "request_hash" field.
func (_u *BatchImageItemUpdate) SetRequestHash(v string) *BatchImageItemUpdate {
	_u.mutation.SetRequestHash(v)
	return _u
}

// SetNillableRequestHash sets the "request_hash" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableRequestHash(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetRequestHash(*v)
	}
	return _u
}

// ClearRequestHash clears the value of the "request_hash" field.
func (_u *BatchImageItemUpdate) ClearRequestHash() *BatchImageItemUpdate {
	_u.mutation.ClearRequestHash()
	return _u
}

// SetPromptPreview sets the "prompt_preview" field.
func (_u *BatchImageItemUpdate) SetPromptPreview(v string) *BatchImageItemUpdate {
	_u.mutation.SetPromptPreview(v)
	return _u
}

// SetNillablePromptPreview sets the "prompt_preview" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillablePromptPreview(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetPromptPreview(*v)
	}
	return _u
}

// ClearPromptPreview clears the value of the "prompt_preview" field.
func (_u *BatchImageItemUpdate) ClearPromptPreview() *BatchImageItemUpdate {
	_u.mutation.ClearPromptPreview()
	return _u
}

// SetProviderSourceObject sets the "provider_source_object" field.
func (_u *BatchImageItemUpdate) SetProviderSourceObject(v string) *BatchImageItemUpdate {
	_u.mutation.SetProviderSourceObject(v)
	return _u
}

// SetNillableProviderSourceObject sets the "provider_source_object" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableProviderSourceObject(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetProviderSourceObject(*v)
	}
	return _u
}

// ClearProviderSourceObject clears the value of the "provider_source_object" field.
func (_u *BatchImageItemUpdate) ClearProviderSourceObject() *BatchImageItemUpdate {
	_u.mutation.ClearProviderSourceObject()
	return _u
}

// SetSourceLineNumber sets the "source_line_number" field.
func (_u *BatchImageItemUpdate) SetSourceLineNumber(v int) *BatchImageItemUpdate {
	_u.mutation.ResetSourceLineNumber()
	_u.mutation.SetSourceLineNumber(v)
	return _u
}

// SetNillableSourceLineNumber sets the "source_line_number" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableSourceLineNumber(v *int) *BatchImageItemUpdate {
	if v != nil {
		_u.SetSourceLineNumber(*v)
	}
	return _u
}

// AddSourceLineNumber adds value to the "source_line_number" field.
func (_u *BatchImageItemUpdate) AddSourceLineNumber(v int) *BatchImageItemUpdate {
	_u.mutation.AddSourceLineNumber(v)
	return _u
}

// ClearSourceLineNumber clears the value of the "source_line_number" field.
func (_u *BatchImageItemUpdate) ClearSourceLineNumber() *BatchImageItemUpdate {
	_u.mutation.ClearSourceLineNumber()
	return _u
}

// SetSourceByteOffset sets the "source_byte_offset" field.
func (_u *BatchImageItemUpdate) SetSourceByteOffset(v int64) *BatchImageItemUpdate {
	_u.mutation.ResetSourceByteOffset()
	_u.mutation.SetSourceByteOffset(v)
	return _u
}

// SetNillableSourceByteOffset sets the "source_byte_offset" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableSourceByteOffset(v *int64) *BatchImageItemUpdate {
	if v != nil {
		_u.SetSourceByteOffset(*v)
	}
	return _u
}

// AddSourceByteOffset adds value to the "source_byte_offset" field.
func (_u *BatchImageItemUpdate) AddSourceByteOffset(v int64) *BatchImageItemUpdate {
	_u.mutation.AddSourceByteOffset(v)
	return _u
}

// ClearSourceByteOffset clears the value of the "source_byte_offset" field.
func (_u *BatchImageItemUpdate) ClearSourceByteOffset() *BatchImageItemUpdate {
	_u.mutation.ClearSourceByteOffset()
	return _u
}

// SetSourceByteLength sets the "source_byte_length" field.
func (_u *BatchImageItemUpdate) SetSourceByteLength(v int64) *BatchImageItemUpdate {
	_u.mutation.ResetSourceByteLength()
	_u.mutation.SetSourceByteLength(v)
	return _u
}

// SetNillableSourceByteLength sets the "source_byte_length" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableSourceByteLength(v *int64) *BatchImageItemUpdate {
	if v != nil {
		_u.SetSourceByteLength(*v)
	}
	return _u
}

// AddSourceByteLength adds value to the "source_byte_length" field.
func (_u *BatchImageItemUpdate) AddSourceByteLength(v int64) *BatchImageItemUpdate {
	_u.mutation.AddSourceByteLength(v)
	return _u
}

// ClearSourceByteLength clears the value of the "source_byte_length" field.
func (_u *BatchImageItemUpdate) ClearSourceByteLength() *BatchImageItemUpdate {
	_u.mutation.ClearSourceByteLength()
	return _u
}

// SetMimeType sets the "mime_type" field.
func (_u *BatchImageItemUpdate) SetMimeType(v string) *BatchImageItemUpdate {
	_u.mutation.SetMimeType(v)
	return _u
}

// SetNillableMimeType sets the "mime_type" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableMimeType(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetMimeType(*v)
	}
	return _u
}

// ClearMimeType clears the value of the "mime_type" field.
func (_u *BatchImageItemUpdate) ClearMimeType() *BatchImageItemUpdate {
	_u.mutation.ClearMimeType()
	return _u
}

// SetFileExtension sets the "file_extension" field.
func (_u *BatchImageItemUpdate) SetFileExtension(v string) *BatchImageItemUpdate {
	_u.mutation.SetFileExtension(v)
	return _u
}

// SetNillableFileExtension sets the "file_extension" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableFileExtension(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetFileExtension(*v)
	}
	return _u
}

// ClearFileExtension clears the value of the "file_extension" field.
func (_u *BatchImageItemUpdate) ClearFileExtension() *BatchImageItemUpdate {
	_u.mutation.ClearFileExtension()
	return _u
}

// SetImageCount sets the "image_count" field.
func (_u *BatchImageItemUpdate) SetImageCount(v int) *BatchImageItemUpdate {
	_u.mutation.ResetImageCount()
	_u.mutation.SetImageCount(v)
	return _u
}

// SetNillableImageCount sets the "image_count" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableImageCount(v *int) *BatchImageItemUpdate {
	if v != nil {
		_u.SetImageCount(*v)
	}
	return _u
}

// AddImageCount adds value to the "image_count" field.
func (_u *BatchImageItemUpdate) AddImageCount(v int) *BatchImageItemUpdate {
	_u.mutation.AddImageCount(v)
	return _u
}

// SetErrorCode sets the "error_code" field.
func (_u *BatchImageItemUpdate) SetErrorCode(v string) *BatchImageItemUpdate {
	_u.mutation.SetErrorCode(v)
	return _u
}

// SetNillableErrorCode sets the "error_code" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableErrorCode(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetErrorCode(*v)
	}
	return _u
}

// ClearErrorCode clears the value of the "error_code" field.
func (_u *BatchImageItemUpdate) ClearErrorCode() *BatchImageItemUpdate {
	_u.mutation.ClearErrorCode()
	return _u
}

// SetErrorMessage sets the "error_message" field.
func (_u *BatchImageItemUpdate) SetErrorMessage(v string) *BatchImageItemUpdate {
	_u.mutation.SetErrorMessage(v)
	return _u
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableErrorMessage(v *string) *BatchImageItemUpdate {
	if v != nil {
		_u.SetErrorMessage(*v)
	}
	return _u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (_u *BatchImageItemUpdate) ClearErrorMessage() *BatchImageItemUpdate {
	_u.mutation.ClearErrorMessage()
	return _u
}

// SetBilledAmount sets the "billed_amount" field.
func (_u *BatchImageItemUpdate) SetBilledAmount(v float64) *BatchImageItemUpdate {
	_u.mutation.ResetBilledAmount()
	_u.mutation.SetBilledAmount(v)
	return _u
}

// SetNillableBilledAmount sets the "billed_amount" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableBilledAmount(v *float64) *BatchImageItemUpdate {
	if v != nil {
		_u.SetBilledAmount(*v)
	}
	return _u
}

// AddBilledAmount adds value to the "billed_amount" field.
func (_u *BatchImageItemUpdate) AddBilledAmount(v float64) *BatchImageItemUpdate {
	_u.mutation.AddBilledAmount(v)
	return _u
}

// ClearBilledAmount clears the value of the "billed_amount" field.
func (_u *BatchImageItemUpdate) ClearBilledAmount() *BatchImageItemUpdate {
	_u.mutation.ClearBilledAmount()
	return _u
}

// SetIndexedAt sets the "indexed_at" field.
func (_u *BatchImageItemUpdate) SetIndexedAt(v time.Time) *BatchImageItemUpdate {
	_u.mutation.SetIndexedAt(v)
	return _u
}

// SetNillableIndexedAt sets the "indexed_at" field if the given value is not nil.
func (_u *BatchImageItemUpdate) SetNillableIndexedAt(v *time.Time) *BatchImageItemUpdate {
	if v != nil {
		_u.SetIndexedAt(*v)
	}
	return _u
}

// ClearIndexedAt clears the value of the "indexed_at" field.
func (_u *BatchImageItemUpdate) ClearIndexedAt() *BatchImageItemUpdate {
	_u.mutation.ClearIndexedAt()
	return _u
}

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

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *BatchImageItemUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *BatchImageItemUpdate) check() error {
	if v, ok := _u.mutation.JobID(); ok {
		if err := batchimageitem.JobIDValidator(v); err != nil {
			return &ValidationError{Name: "job_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.job_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.CustomID(); ok {
		if err := batchimageitem.CustomIDValidator(v); err != nil {
			return &ValidationError{Name: "custom_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.custom_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := batchimageitem.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RequestHash(); ok {
		if err := batchimageitem.RequestHashValidator(v); err != nil {
			return &ValidationError{Name: "request_hash", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.request_hash": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ProviderSourceObject(); ok {
		if err := batchimageitem.ProviderSourceObjectValidator(v); err != nil {
			return &ValidationError{Name: "provider_source_object", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.provider_source_object": %w`, err)}
		}
	}
	if v, ok := _u.mutation.MimeType(); ok {
		if err := batchimageitem.MimeTypeValidator(v); err != nil {
			return &ValidationError{Name: "mime_type", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.mime_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.FileExtension(); ok {
		if err := batchimageitem.FileExtensionValidator(v); err != nil {
			return &ValidationError{Name: "file_extension", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.file_extension": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ErrorCode(); ok {
		if err := batchimageitem.ErrorCodeValidator(v); err != nil {
			return &ValidationError{Name: "error_code", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.error_code": %w`, err)}
		}
	}
	return nil
}

func (_u *BatchImageItemUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(batchimageitem.Table, batchimageitem.Columns, sqlgraph.NewFieldSpec(batchimageitem.FieldID, field.TypeInt64))
	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.JobID(); ok {
		_spec.SetField(batchimageitem.FieldJobID, field.TypeString, value)
	}
	if value, ok := _u.mutation.CustomID(); ok {
		_spec.SetField(batchimageitem.FieldCustomID, field.TypeString, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(batchimageitem.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.RequestHash(); ok {
		_spec.SetField(batchimageitem.FieldRequestHash, field.TypeString, value)
	}
	if _u.mutation.RequestHashCleared() {
		_spec.ClearField(batchimageitem.FieldRequestHash, field.TypeString)
	}
	if value, ok := _u.mutation.PromptPreview(); ok {
		_spec.SetField(batchimageitem.FieldPromptPreview, field.TypeString, value)
	}
	if _u.mutation.PromptPreviewCleared() {
		_spec.ClearField(batchimageitem.FieldPromptPreview, field.TypeString)
	}
	if value, ok := _u.mutation.ProviderSourceObject(); ok {
		_spec.SetField(batchimageitem.FieldProviderSourceObject, field.TypeString, value)
	}
	if _u.mutation.ProviderSourceObjectCleared() {
		_spec.ClearField(batchimageitem.FieldProviderSourceObject, field.TypeString)
	}
	if value, ok := _u.mutation.SourceLineNumber(); ok {
		_spec.SetField(batchimageitem.FieldSourceLineNumber, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedSourceLineNumber(); ok {
		_spec.AddField(batchimageitem.FieldSourceLineNumber, field.TypeInt, value)
	}
	if _u.mutation.SourceLineNumberCleared() {
		_spec.ClearField(batchimageitem.FieldSourceLineNumber, field.TypeInt)
	}
	if value, ok := _u.mutation.SourceByteOffset(); ok {
		_spec.SetField(batchimageitem.FieldSourceByteOffset, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSourceByteOffset(); ok {
		_spec.AddField(batchimageitem.FieldSourceByteOffset, field.TypeInt64, value)
	}
	if _u.mutation.SourceByteOffsetCleared() {
		_spec.ClearField(batchimageitem.FieldSourceByteOffset, field.TypeInt64)
	}
	if value, ok := _u.mutation.SourceByteLength(); ok {
		_spec.SetField(batchimageitem.FieldSourceByteLength, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSourceByteLength(); ok {
		_spec.AddField(batchimageitem.FieldSourceByteLength, field.TypeInt64, value)
	}
	if _u.mutation.SourceByteLengthCleared() {
		_spec.ClearField(batchimageitem.FieldSourceByteLength, field.TypeInt64)
	}
	if value, ok := _u.mutation.MimeType(); ok {
		_spec.SetField(batchimageitem.FieldMimeType, field.TypeString, value)
	}
	if _u.mutation.MimeTypeCleared() {
		_spec.ClearField(batchimageitem.FieldMimeType, field.TypeString)
	}
	if value, ok := _u.mutation.FileExtension(); ok {
		_spec.SetField(batchimageitem.FieldFileExtension, field.TypeString, value)
	}
	if _u.mutation.FileExtensionCleared() {
		_spec.ClearField(batchimageitem.FieldFileExtension, field.TypeString)
	}
	if value, ok := _u.mutation.ImageCount(); ok {
		_spec.SetField(batchimageitem.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedImageCount(); ok {
		_spec.AddField(batchimageitem.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ErrorCode(); ok {
		_spec.SetField(batchimageitem.FieldErrorCode, field.TypeString, value)
	}
	if _u.mutation.ErrorCodeCleared() {
		_spec.ClearField(batchimageitem.FieldErrorCode, field.TypeString)
	}
	if value, ok := _u.mutation.ErrorMessage(); ok {
		_spec.SetField(batchimageitem.FieldErrorMessage, field.TypeString, value)
	}
	if _u.mutation.ErrorMessageCleared() {
		_spec.ClearField(batchimageitem.FieldErrorMessage, field.TypeString)
	}
	if value, ok := _u.mutation.BilledAmount(); ok {
		_spec.SetField(batchimageitem.FieldBilledAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedBilledAmount(); ok {
		_spec.AddField(batchimageitem.FieldBilledAmount, field.TypeFloat64, value)
	}
	if _u.mutation.BilledAmountCleared() {
		_spec.ClearField(batchimageitem.FieldBilledAmount, field.TypeFloat64)
	}
	if value, ok := _u.mutation.IndexedAt(); ok {
		_spec.SetField(batchimageitem.FieldIndexedAt, field.TypeTime, value)
	}
	if _u.mutation.IndexedAtCleared() {
		_spec.ClearField(batchimageitem.FieldIndexedAt, field.TypeTime)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{batchimageitem.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// BatchImageItemUpdateOne is the builder for updating a single BatchImageItem entity.
type BatchImageItemUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *BatchImageItemMutation
}

// SetJobID sets the "job_id" field.
func (_u *BatchImageItemUpdateOne) SetJobID(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetJobID(v)
	return _u
}

// SetNillableJobID sets the "job_id" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableJobID(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetJobID(*v)
	}
	return _u
}

// SetCustomID sets the "custom_id" field.
func (_u *BatchImageItemUpdateOne) SetCustomID(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetCustomID(v)
	return _u
}

// SetNillableCustomID sets the "custom_id" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableCustomID(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetCustomID(*v)
	}
	return _u
}

// SetStatus sets the "status" field.
func (_u *BatchImageItemUpdateOne) SetStatus(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetStatus(v)
	return _u
}

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

// SetRequestHash sets the "request_hash" field.
func (_u *BatchImageItemUpdateOne) SetRequestHash(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetRequestHash(v)
	return _u
}

// SetNillableRequestHash sets the "request_hash" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableRequestHash(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetRequestHash(*v)
	}
	return _u
}

// ClearRequestHash clears the value of the "request_hash" field.
func (_u *BatchImageItemUpdateOne) ClearRequestHash() *BatchImageItemUpdateOne {
	_u.mutation.ClearRequestHash()
	return _u
}

// SetPromptPreview sets the "prompt_preview" field.
func (_u *BatchImageItemUpdateOne) SetPromptPreview(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetPromptPreview(v)
	return _u
}

// SetNillablePromptPreview sets the "prompt_preview" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillablePromptPreview(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetPromptPreview(*v)
	}
	return _u
}

// ClearPromptPreview clears the value of the "prompt_preview" field.
func (_u *BatchImageItemUpdateOne) ClearPromptPreview() *BatchImageItemUpdateOne {
	_u.mutation.ClearPromptPreview()
	return _u
}

// SetProviderSourceObject sets the "provider_source_object" field.
func (_u *BatchImageItemUpdateOne) SetProviderSourceObject(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetProviderSourceObject(v)
	return _u
}

// SetNillableProviderSourceObject sets the "provider_source_object" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableProviderSourceObject(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetProviderSourceObject(*v)
	}
	return _u
}

// ClearProviderSourceObject clears the value of the "provider_source_object" field.
func (_u *BatchImageItemUpdateOne) ClearProviderSourceObject() *BatchImageItemUpdateOne {
	_u.mutation.ClearProviderSourceObject()
	return _u
}

// SetSourceLineNumber sets the "source_line_number" field.
func (_u *BatchImageItemUpdateOne) SetSourceLineNumber(v int) *BatchImageItemUpdateOne {
	_u.mutation.ResetSourceLineNumber()
	_u.mutation.SetSourceLineNumber(v)
	return _u
}

// SetNillableSourceLineNumber sets the "source_line_number" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableSourceLineNumber(v *int) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetSourceLineNumber(*v)
	}
	return _u
}

// AddSourceLineNumber adds value to the "source_line_number" field.
func (_u *BatchImageItemUpdateOne) AddSourceLineNumber(v int) *BatchImageItemUpdateOne {
	_u.mutation.AddSourceLineNumber(v)
	return _u
}

// ClearSourceLineNumber clears the value of the "source_line_number" field.
func (_u *BatchImageItemUpdateOne) ClearSourceLineNumber() *BatchImageItemUpdateOne {
	_u.mutation.ClearSourceLineNumber()
	return _u
}

// SetSourceByteOffset sets the "source_byte_offset" field.
func (_u *BatchImageItemUpdateOne) SetSourceByteOffset(v int64) *BatchImageItemUpdateOne {
	_u.mutation.ResetSourceByteOffset()
	_u.mutation.SetSourceByteOffset(v)
	return _u
}

// SetNillableSourceByteOffset sets the "source_byte_offset" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableSourceByteOffset(v *int64) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetSourceByteOffset(*v)
	}
	return _u
}

// AddSourceByteOffset adds value to the "source_byte_offset" field.
func (_u *BatchImageItemUpdateOne) AddSourceByteOffset(v int64) *BatchImageItemUpdateOne {
	_u.mutation.AddSourceByteOffset(v)
	return _u
}

// ClearSourceByteOffset clears the value of the "source_byte_offset" field.
func (_u *BatchImageItemUpdateOne) ClearSourceByteOffset() *BatchImageItemUpdateOne {
	_u.mutation.ClearSourceByteOffset()
	return _u
}

// SetSourceByteLength sets the "source_byte_length" field.
func (_u *BatchImageItemUpdateOne) SetSourceByteLength(v int64) *BatchImageItemUpdateOne {
	_u.mutation.ResetSourceByteLength()
	_u.mutation.SetSourceByteLength(v)
	return _u
}

// SetNillableSourceByteLength sets the "source_byte_length" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableSourceByteLength(v *int64) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetSourceByteLength(*v)
	}
	return _u
}

// AddSourceByteLength adds value to the "source_byte_length" field.
func (_u *BatchImageItemUpdateOne) AddSourceByteLength(v int64) *BatchImageItemUpdateOne {
	_u.mutation.AddSourceByteLength(v)
	return _u
}

// ClearSourceByteLength clears the value of the "source_byte_length" field.
func (_u *BatchImageItemUpdateOne) ClearSourceByteLength() *BatchImageItemUpdateOne {
	_u.mutation.ClearSourceByteLength()
	return _u
}

// SetMimeType sets the "mime_type" field.
func (_u *BatchImageItemUpdateOne) SetMimeType(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetMimeType(v)
	return _u
}

// SetNillableMimeType sets the "mime_type" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableMimeType(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetMimeType(*v)
	}
	return _u
}

// ClearMimeType clears the value of the "mime_type" field.
func (_u *BatchImageItemUpdateOne) ClearMimeType() *BatchImageItemUpdateOne {
	_u.mutation.ClearMimeType()
	return _u
}

// SetFileExtension sets the "file_extension" field.
func (_u *BatchImageItemUpdateOne) SetFileExtension(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetFileExtension(v)
	return _u
}

// SetNillableFileExtension sets the "file_extension" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableFileExtension(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetFileExtension(*v)
	}
	return _u
}

// ClearFileExtension clears the value of the "file_extension" field.
func (_u *BatchImageItemUpdateOne) ClearFileExtension() *BatchImageItemUpdateOne {
	_u.mutation.ClearFileExtension()
	return _u
}

// SetImageCount sets the "image_count" field.
func (_u *BatchImageItemUpdateOne) SetImageCount(v int) *BatchImageItemUpdateOne {
	_u.mutation.ResetImageCount()
	_u.mutation.SetImageCount(v)
	return _u
}

// SetNillableImageCount sets the "image_count" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableImageCount(v *int) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetImageCount(*v)
	}
	return _u
}

// AddImageCount adds value to the "image_count" field.
func (_u *BatchImageItemUpdateOne) AddImageCount(v int) *BatchImageItemUpdateOne {
	_u.mutation.AddImageCount(v)
	return _u
}

// SetErrorCode sets the "error_code" field.
func (_u *BatchImageItemUpdateOne) SetErrorCode(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetErrorCode(v)
	return _u
}

// SetNillableErrorCode sets the "error_code" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableErrorCode(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetErrorCode(*v)
	}
	return _u
}

// ClearErrorCode clears the value of the "error_code" field.
func (_u *BatchImageItemUpdateOne) ClearErrorCode() *BatchImageItemUpdateOne {
	_u.mutation.ClearErrorCode()
	return _u
}

// SetErrorMessage sets the "error_message" field.
func (_u *BatchImageItemUpdateOne) SetErrorMessage(v string) *BatchImageItemUpdateOne {
	_u.mutation.SetErrorMessage(v)
	return _u
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableErrorMessage(v *string) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetErrorMessage(*v)
	}
	return _u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (_u *BatchImageItemUpdateOne) ClearErrorMessage() *BatchImageItemUpdateOne {
	_u.mutation.ClearErrorMessage()
	return _u
}

// SetBilledAmount sets the "billed_amount" field.
func (_u *BatchImageItemUpdateOne) SetBilledAmount(v float64) *BatchImageItemUpdateOne {
	_u.mutation.ResetBilledAmount()
	_u.mutation.SetBilledAmount(v)
	return _u
}

// SetNillableBilledAmount sets the "billed_amount" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableBilledAmount(v *float64) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetBilledAmount(*v)
	}
	return _u
}

// AddBilledAmount adds value to the "billed_amount" field.
func (_u *BatchImageItemUpdateOne) AddBilledAmount(v float64) *BatchImageItemUpdateOne {
	_u.mutation.AddBilledAmount(v)
	return _u
}

// ClearBilledAmount clears the value of the "billed_amount" field.
func (_u *BatchImageItemUpdateOne) ClearBilledAmount() *BatchImageItemUpdateOne {
	_u.mutation.ClearBilledAmount()
	return _u
}

// SetIndexedAt sets the "indexed_at" field.
func (_u *BatchImageItemUpdateOne) SetIndexedAt(v time.Time) *BatchImageItemUpdateOne {
	_u.mutation.SetIndexedAt(v)
	return _u
}

// SetNillableIndexedAt sets the "indexed_at" field if the given value is not nil.
func (_u *BatchImageItemUpdateOne) SetNillableIndexedAt(v *time.Time) *BatchImageItemUpdateOne {
	if v != nil {
		_u.SetIndexedAt(*v)
	}
	return _u
}

// ClearIndexedAt clears the value of the "indexed_at" field.
func (_u *BatchImageItemUpdateOne) ClearIndexedAt() *BatchImageItemUpdateOne {
	_u.mutation.ClearIndexedAt()
	return _u
}

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

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

// Save executes the query and returns the updated BatchImageItem entity.
func (_u *BatchImageItemUpdateOne) Save(ctx context.Context) (*BatchImageItem, error) {
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *BatchImageItemUpdateOne) check() error {
	if v, ok := _u.mutation.JobID(); ok {
		if err := batchimageitem.JobIDValidator(v); err != nil {
			return &ValidationError{Name: "job_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.job_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.CustomID(); ok {
		if err := batchimageitem.CustomIDValidator(v); err != nil {
			return &ValidationError{Name: "custom_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.custom_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := batchimageitem.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RequestHash(); ok {
		if err := batchimageitem.RequestHashValidator(v); err != nil {
			return &ValidationError{Name: "request_hash", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.request_hash": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ProviderSourceObject(); ok {
		if err := batchimageitem.ProviderSourceObjectValidator(v); err != nil {
			return &ValidationError{Name: "provider_source_object", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.provider_source_object": %w`, err)}
		}
	}
	if v, ok := _u.mutation.MimeType(); ok {
		if err := batchimageitem.MimeTypeValidator(v); err != nil {
			return &ValidationError{Name: "mime_type", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.mime_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.FileExtension(); ok {
		if err := batchimageitem.FileExtensionValidator(v); err != nil {
			return &ValidationError{Name: "file_extension", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.file_extension": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ErrorCode(); ok {
		if err := batchimageitem.ErrorCodeValidator(v); err != nil {
			return &ValidationError{Name: "error_code", err: fmt.Errorf(`ent: validator failed for field "BatchImageItem.error_code": %w`, err)}
		}
	}
	return nil
}

func (_u *BatchImageItemUpdateOne) sqlSave(ctx context.Context) (_node *BatchImageItem, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(batchimageitem.Table, batchimageitem.Columns, sqlgraph.NewFieldSpec(batchimageitem.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchImageItem.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, batchimageitem.FieldID)
		for _, f := range fields {
			if !batchimageitem.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != batchimageitem.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.JobID(); ok {
		_spec.SetField(batchimageitem.FieldJobID, field.TypeString, value)
	}
	if value, ok := _u.mutation.CustomID(); ok {
		_spec.SetField(batchimageitem.FieldCustomID, field.TypeString, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(batchimageitem.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.RequestHash(); ok {
		_spec.SetField(batchimageitem.FieldRequestHash, field.TypeString, value)
	}
	if _u.mutation.RequestHashCleared() {
		_spec.ClearField(batchimageitem.FieldRequestHash, field.TypeString)
	}
	if value, ok := _u.mutation.PromptPreview(); ok {
		_spec.SetField(batchimageitem.FieldPromptPreview, field.TypeString, value)
	}
	if _u.mutation.PromptPreviewCleared() {
		_spec.ClearField(batchimageitem.FieldPromptPreview, field.TypeString)
	}
	if value, ok := _u.mutation.ProviderSourceObject(); ok {
		_spec.SetField(batchimageitem.FieldProviderSourceObject, field.TypeString, value)
	}
	if _u.mutation.ProviderSourceObjectCleared() {
		_spec.ClearField(batchimageitem.FieldProviderSourceObject, field.TypeString)
	}
	if value, ok := _u.mutation.SourceLineNumber(); ok {
		_spec.SetField(batchimageitem.FieldSourceLineNumber, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedSourceLineNumber(); ok {
		_spec.AddField(batchimageitem.FieldSourceLineNumber, field.TypeInt, value)
	}
	if _u.mutation.SourceLineNumberCleared() {
		_spec.ClearField(batchimageitem.FieldSourceLineNumber, field.TypeInt)
	}
	if value, ok := _u.mutation.SourceByteOffset(); ok {
		_spec.SetField(batchimageitem.FieldSourceByteOffset, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSourceByteOffset(); ok {
		_spec.AddField(batchimageitem.FieldSourceByteOffset, field.TypeInt64, value)
	}
	if _u.mutation.SourceByteOffsetCleared() {
		_spec.ClearField(batchimageitem.FieldSourceByteOffset, field.TypeInt64)
	}
	if value, ok := _u.mutation.SourceByteLength(); ok {
		_spec.SetField(batchimageitem.FieldSourceByteLength, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSourceByteLength(); ok {
		_spec.AddField(batchimageitem.FieldSourceByteLength, field.TypeInt64, value)
	}
	if _u.mutation.SourceByteLengthCleared() {
		_spec.ClearField(batchimageitem.FieldSourceByteLength, field.TypeInt64)
	}
	if value, ok := _u.mutation.MimeType(); ok {
		_spec.SetField(batchimageitem.FieldMimeType, field.TypeString, value)
	}
	if _u.mutation.MimeTypeCleared() {
		_spec.ClearField(batchimageitem.FieldMimeType, field.TypeString)
	}
	if value, ok := _u.mutation.FileExtension(); ok {
		_spec.SetField(batchimageitem.FieldFileExtension, field.TypeString, value)
	}
	if _u.mutation.FileExtensionCleared() {
		_spec.ClearField(batchimageitem.FieldFileExtension, field.TypeString)
	}
	if value, ok := _u.mutation.ImageCount(); ok {
		_spec.SetField(batchimageitem.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedImageCount(); ok {
		_spec.AddField(batchimageitem.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ErrorCode(); ok {
		_spec.SetField(batchimageitem.FieldErrorCode, field.TypeString, value)
	}
	if _u.mutation.ErrorCodeCleared() {
		_spec.ClearField(batchimageitem.FieldErrorCode, field.TypeString)
	}
	if value, ok := _u.mutation.ErrorMessage(); ok {
		_spec.SetField(batchimageitem.FieldErrorMessage, field.TypeString, value)
	}
	if _u.mutation.ErrorMessageCleared() {
		_spec.ClearField(batchimageitem.FieldErrorMessage, field.TypeString)
	}
	if value, ok := _u.mutation.BilledAmount(); ok {
		_spec.SetField(batchimageitem.FieldBilledAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedBilledAmount(); ok {
		_spec.AddField(batchimageitem.FieldBilledAmount, field.TypeFloat64, value)
	}
	if _u.mutation.BilledAmountCleared() {
		_spec.ClearField(batchimageitem.FieldBilledAmount, field.TypeFloat64)
	}
	if value, ok := _u.mutation.IndexedAt(); ok {
		_spec.SetField(batchimageitem.FieldIndexedAt, field.TypeTime, value)
	}
	if _u.mutation.IndexedAtCleared() {
		_spec.ClearField(batchimageitem.FieldIndexedAt, field.TypeTime)
	}
	_node = &BatchImageItem{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{batchimageitem.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
