// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"registry-backend/ent/storagefile"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
)

// StorageFile is the model entity for the StorageFile schema.
type StorageFile struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// CreateTime holds the value of the "create_time" field.
	CreateTime time.Time `json:"create_time,omitempty"`
	// UpdateTime holds the value of the "update_time" field.
	UpdateTime time.Time `json:"update_time,omitempty"`
	// BucketName holds the value of the "bucket_name" field.
	BucketName string `json:"bucket_name,omitempty"`
	// ObjectName holds the value of the "object_name" field.
	ObjectName string `json:"object_name,omitempty"`
	// FilePath holds the value of the "file_path" field.
	FilePath string `json:"file_path,omitempty"`
	// e.g., image, video
	FileType string `json:"file_type,omitempty"`
	// Publicly accessible URL of the file, if available
	FileURL                         string `json:"file_url,omitempty"`
	ci_workflow_result_storage_file *uuid.UUID
	selectValues                    sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*StorageFile) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case storagefile.FieldBucketName, storagefile.FieldObjectName, storagefile.FieldFilePath, storagefile.FieldFileType, storagefile.FieldFileURL:
			values[i] = new(sql.NullString)
		case storagefile.FieldCreateTime, storagefile.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case storagefile.FieldID:
			values[i] = new(uuid.UUID)
		case storagefile.ForeignKeys[0]: // ci_workflow_result_storage_file
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the StorageFile fields.
func (sf *StorageFile) 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 storagefile.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				sf.ID = *value
			}
		case storagefile.FieldCreateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field create_time", values[i])
			} else if value.Valid {
				sf.CreateTime = value.Time
			}
		case storagefile.FieldUpdateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field update_time", values[i])
			} else if value.Valid {
				sf.UpdateTime = value.Time
			}
		case storagefile.FieldBucketName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field bucket_name", values[i])
			} else if value.Valid {
				sf.BucketName = value.String
			}
		case storagefile.FieldObjectName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field object_name", values[i])
			} else if value.Valid {
				sf.ObjectName = value.String
			}
		case storagefile.FieldFilePath:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field file_path", values[i])
			} else if value.Valid {
				sf.FilePath = value.String
			}
		case storagefile.FieldFileType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field file_type", values[i])
			} else if value.Valid {
				sf.FileType = value.String
			}
		case storagefile.FieldFileURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field file_url", values[i])
			} else if value.Valid {
				sf.FileURL = value.String
			}
		case storagefile.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field ci_workflow_result_storage_file", values[i])
			} else if value.Valid {
				sf.ci_workflow_result_storage_file = new(uuid.UUID)
				*sf.ci_workflow_result_storage_file = *value.S.(*uuid.UUID)
			}
		default:
			sf.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (sf *StorageFile) String() string {
	var builder strings.Builder
	builder.WriteString("StorageFile(")
	builder.WriteString(fmt.Sprintf("id=%v, ", sf.ID))
	builder.WriteString("create_time=")
	builder.WriteString(sf.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(sf.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("bucket_name=")
	builder.WriteString(sf.BucketName)
	builder.WriteString(", ")
	builder.WriteString("object_name=")
	builder.WriteString(sf.ObjectName)
	builder.WriteString(", ")
	builder.WriteString("file_path=")
	builder.WriteString(sf.FilePath)
	builder.WriteString(", ")
	builder.WriteString("file_type=")
	builder.WriteString(sf.FileType)
	builder.WriteString(", ")
	builder.WriteString("file_url=")
	builder.WriteString(sf.FileURL)
	builder.WriteByte(')')
	return builder.String()
}

// StorageFiles is a parsable slice of StorageFile.
type StorageFiles []*StorageFile
