// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/buildbarn/bb-portal/ent/gen/ent/blob"
)

// Blob is the model entity for the Blob schema.
type Blob struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// URI holds the value of the "uri" field.
	URI string `json:"uri,omitempty"`
	// SizeBytes holds the value of the "size_bytes" field.
	SizeBytes int64 `json:"size_bytes,omitempty"`
	// ArchivingStatus holds the value of the "archiving_status" field.
	ArchivingStatus blob.ArchivingStatus `json:"archiving_status,omitempty"`
	// Reason holds the value of the "reason" field.
	Reason string `json:"reason,omitempty"`
	// ArchiveURL holds the value of the "archive_url" field.
	ArchiveURL string `json:"archive_url,omitempty"`
	// InstanceName holds the value of the "instance_name" field.
	InstanceName string `json:"instance_name,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Blob) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case blob.FieldID, blob.FieldSizeBytes:
			values[i] = new(sql.NullInt64)
		case blob.FieldURI, blob.FieldArchivingStatus, blob.FieldReason, blob.FieldArchiveURL, blob.FieldInstanceName:
			values[i] = new(sql.NullString)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Blob fields.
func (b *Blob) 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 blob.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			b.ID = int(value.Int64)
		case blob.FieldURI:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field uri", values[i])
			} else if value.Valid {
				b.URI = value.String
			}
		case blob.FieldSizeBytes:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field size_bytes", values[i])
			} else if value.Valid {
				b.SizeBytes = value.Int64
			}
		case blob.FieldArchivingStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field archiving_status", values[i])
			} else if value.Valid {
				b.ArchivingStatus = blob.ArchivingStatus(value.String)
			}
		case blob.FieldReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field reason", values[i])
			} else if value.Valid {
				b.Reason = value.String
			}
		case blob.FieldArchiveURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field archive_url", values[i])
			} else if value.Valid {
				b.ArchiveURL = value.String
			}
		case blob.FieldInstanceName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field instance_name", values[i])
			} else if value.Valid {
				b.InstanceName = value.String
			}
		default:
			b.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

// Unwrap unwraps the Blob 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 (b *Blob) Unwrap() *Blob {
	_tx, ok := b.config.driver.(*txDriver)
	if !ok {
		panic("ent: Blob is not a transactional entity")
	}
	b.config.driver = _tx.drv
	return b
}

// String implements the fmt.Stringer.
func (b *Blob) String() string {
	var builder strings.Builder
	builder.WriteString("Blob(")
	builder.WriteString(fmt.Sprintf("id=%v, ", b.ID))
	builder.WriteString("uri=")
	builder.WriteString(b.URI)
	builder.WriteString(", ")
	builder.WriteString("size_bytes=")
	builder.WriteString(fmt.Sprintf("%v", b.SizeBytes))
	builder.WriteString(", ")
	builder.WriteString("archiving_status=")
	builder.WriteString(fmt.Sprintf("%v", b.ArchivingStatus))
	builder.WriteString(", ")
	builder.WriteString("reason=")
	builder.WriteString(b.Reason)
	builder.WriteString(", ")
	builder.WriteString("archive_url=")
	builder.WriteString(b.ArchiveURL)
	builder.WriteString(", ")
	builder.WriteString("instance_name=")
	builder.WriteString(b.InstanceName)
	builder.WriteByte(')')
	return builder.String()
}

// Blobs is a parsable slice of Blob.
type Blobs []*Blob
