// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/Wei-Shaw/sub2api/ent/batchimageitem"
)

// BatchImageItem is the model entity for the BatchImageItem schema.
type BatchImageItem struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// JobID holds the value of the "job_id" field.
	JobID string `json:"job_id,omitempty"`
	// CustomID holds the value of the "custom_id" field.
	CustomID string `json:"custom_id,omitempty"`
	// Status holds the value of the "status" field.
	Status string `json:"status,omitempty"`
	// RequestHash holds the value of the "request_hash" field.
	RequestHash *string `json:"request_hash,omitempty"`
	// PromptPreview holds the value of the "prompt_preview" field.
	PromptPreview *string `json:"prompt_preview,omitempty"`
	// ProviderSourceObject holds the value of the "provider_source_object" field.
	ProviderSourceObject *string `json:"provider_source_object,omitempty"`
	// SourceLineNumber holds the value of the "source_line_number" field.
	SourceLineNumber *int `json:"source_line_number,omitempty"`
	// SourceByteOffset holds the value of the "source_byte_offset" field.
	SourceByteOffset *int64 `json:"source_byte_offset,omitempty"`
	// SourceByteLength holds the value of the "source_byte_length" field.
	SourceByteLength *int64 `json:"source_byte_length,omitempty"`
	// MimeType holds the value of the "mime_type" field.
	MimeType *string `json:"mime_type,omitempty"`
	// FileExtension holds the value of the "file_extension" field.
	FileExtension *string `json:"file_extension,omitempty"`
	// ImageCount holds the value of the "image_count" field.
	ImageCount int `json:"image_count,omitempty"`
	// ErrorCode holds the value of the "error_code" field.
	ErrorCode *string `json:"error_code,omitempty"`
	// ErrorMessage holds the value of the "error_message" field.
	ErrorMessage *string `json:"error_message,omitempty"`
	// BilledAmount holds the value of the "billed_amount" field.
	BilledAmount *float64 `json:"billed_amount,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// IndexedAt holds the value of the "indexed_at" field.
	IndexedAt    *time.Time `json:"indexed_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*BatchImageItem) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case batchimageitem.FieldBilledAmount:
			values[i] = new(sql.NullFloat64)
		case batchimageitem.FieldID, batchimageitem.FieldSourceLineNumber, batchimageitem.FieldSourceByteOffset, batchimageitem.FieldSourceByteLength, batchimageitem.FieldImageCount:
			values[i] = new(sql.NullInt64)
		case batchimageitem.FieldJobID, batchimageitem.FieldCustomID, batchimageitem.FieldStatus, batchimageitem.FieldRequestHash, batchimageitem.FieldPromptPreview, batchimageitem.FieldProviderSourceObject, batchimageitem.FieldMimeType, batchimageitem.FieldFileExtension, batchimageitem.FieldErrorCode, batchimageitem.FieldErrorMessage:
			values[i] = new(sql.NullString)
		case batchimageitem.FieldCreatedAt, batchimageitem.FieldIndexedAt:
			values[i] = new(sql.NullTime)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the BatchImageItem fields.
func (_m *BatchImageItem) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case batchimageitem.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int64(value.Int64)
		case batchimageitem.FieldJobID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field job_id", values[i])
			} else if value.Valid {
				_m.JobID = value.String
			}
		case batchimageitem.FieldCustomID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field custom_id", values[i])
			} else if value.Valid {
				_m.CustomID = value.String
			}
		case batchimageitem.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				_m.Status = value.String
			}
		case batchimageitem.FieldRequestHash:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field request_hash", values[i])
			} else if value.Valid {
				_m.RequestHash = new(string)
				*_m.RequestHash = value.String
			}
		case batchimageitem.FieldPromptPreview:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field prompt_preview", values[i])
			} else if value.Valid {
				_m.PromptPreview = new(string)
				*_m.PromptPreview = value.String
			}
		case batchimageitem.FieldProviderSourceObject:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field provider_source_object", values[i])
			} else if value.Valid {
				_m.ProviderSourceObject = new(string)
				*_m.ProviderSourceObject = value.String
			}
		case batchimageitem.FieldSourceLineNumber:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field source_line_number", values[i])
			} else if value.Valid {
				_m.SourceLineNumber = new(int)
				*_m.SourceLineNumber = int(value.Int64)
			}
		case batchimageitem.FieldSourceByteOffset:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field source_byte_offset", values[i])
			} else if value.Valid {
				_m.SourceByteOffset = new(int64)
				*_m.SourceByteOffset = value.Int64
			}
		case batchimageitem.FieldSourceByteLength:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field source_byte_length", values[i])
			} else if value.Valid {
				_m.SourceByteLength = new(int64)
				*_m.SourceByteLength = value.Int64
			}
		case batchimageitem.FieldMimeType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field mime_type", values[i])
			} else if value.Valid {
				_m.MimeType = new(string)
				*_m.MimeType = value.String
			}
		case batchimageitem.FieldFileExtension:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field file_extension", values[i])
			} else if value.Valid {
				_m.FileExtension = new(string)
				*_m.FileExtension = value.String
			}
		case batchimageitem.FieldImageCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field image_count", values[i])
			} else if value.Valid {
				_m.ImageCount = int(value.Int64)
			}
		case batchimageitem.FieldErrorCode:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field error_code", values[i])
			} else if value.Valid {
				_m.ErrorCode = new(string)
				*_m.ErrorCode = value.String
			}
		case batchimageitem.FieldErrorMessage:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field error_message", values[i])
			} else if value.Valid {
				_m.ErrorMessage = new(string)
				*_m.ErrorMessage = value.String
			}
		case batchimageitem.FieldBilledAmount:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field billed_amount", values[i])
			} else if value.Valid {
				_m.BilledAmount = new(float64)
				*_m.BilledAmount = value.Float64
			}
		case batchimageitem.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				_m.CreatedAt = value.Time
			}
		case batchimageitem.FieldIndexedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field indexed_at", values[i])
			} else if value.Valid {
				_m.IndexedAt = new(time.Time)
				*_m.IndexedAt = value.Time
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the BatchImageItem.
// This includes values selected through modifiers, order, etc.
func (_m *BatchImageItem) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

// Update returns a builder for updating this BatchImageItem.
// Note that you need to call BatchImageItem.Unwrap() before calling this method if this BatchImageItem
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *BatchImageItem) Update() *BatchImageItemUpdateOne {
	return NewBatchImageItemClient(_m.config).UpdateOne(_m)
}

// Unwrap unwraps the BatchImageItem entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *BatchImageItem) Unwrap() *BatchImageItem {
	_tx, ok := _m.config.driver.(*txDriver)
	if !ok {
		panic("ent: BatchImageItem is not a transactional entity")
	}
	_m.config.driver = _tx.drv
	return _m
}

// String implements the fmt.Stringer.
func (_m *BatchImageItem) String() string {
	var builder strings.Builder
	builder.WriteString("BatchImageItem(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("job_id=")
	builder.WriteString(_m.JobID)
	builder.WriteString(", ")
	builder.WriteString("custom_id=")
	builder.WriteString(_m.CustomID)
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(_m.Status)
	builder.WriteString(", ")
	if v := _m.RequestHash; v != nil {
		builder.WriteString("request_hash=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.PromptPreview; v != nil {
		builder.WriteString("prompt_preview=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.ProviderSourceObject; v != nil {
		builder.WriteString("provider_source_object=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.SourceLineNumber; v != nil {
		builder.WriteString("source_line_number=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	if v := _m.SourceByteOffset; v != nil {
		builder.WriteString("source_byte_offset=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	if v := _m.SourceByteLength; v != nil {
		builder.WriteString("source_byte_length=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	if v := _m.MimeType; v != nil {
		builder.WriteString("mime_type=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.FileExtension; v != nil {
		builder.WriteString("file_extension=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("image_count=")
	builder.WriteString(fmt.Sprintf("%v", _m.ImageCount))
	builder.WriteString(", ")
	if v := _m.ErrorCode; v != nil {
		builder.WriteString("error_code=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.ErrorMessage; v != nil {
		builder.WriteString("error_message=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.BilledAmount; v != nil {
		builder.WriteString("billed_amount=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	if v := _m.IndexedAt; v != nil {
		builder.WriteString("indexed_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// BatchImageItems is a parsable slice of BatchImageItem.
type BatchImageItems []*BatchImageItem
