// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/anzhiyu-c/anheyu-app/ent/album"
)

// Album is the model entity for the Album schema.
type Album struct {
	config `json:"-"`
	// ID of the ent.
	ID uint `json:"id,omitempty"`
	// DeletedAt holds the value of the "deleted_at" field.
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// 图片URL
	ImageURL string `json:"image_url,omitempty"`
	// 大图URL
	BigImageURL string `json:"big_image_url,omitempty"`
	// 下载URL
	DownloadURL string `json:"download_url,omitempty"`
	// 缩略图处理参数
	ThumbParam string `json:"thumb_param,omitempty"`
	// 大图处理参数
	BigParam string `json:"big_param,omitempty"`
	// 标签，逗号分隔
	Tags string `json:"tags,omitempty"`
	// 查看次数
	ViewCount int `json:"view_count,omitempty"`
	// 下载次数
	DownloadCount int `json:"download_count,omitempty"`
	// 图片宽度
	Width int `json:"width,omitempty"`
	// 图片高度
	Height int `json:"height,omitempty"`
	// 文件大小（字节）
	FileSize int64 `json:"file_size,omitempty"`
	// 图片格式
	Format string `json:"format,omitempty"`
	// 图片宽高比
	AspectRatio string `json:"aspect_ratio,omitempty"`
	// 文件哈希值
	FileHash string `json:"file_hash,omitempty"`
	// 排序字段，数字越小越靠前
	DisplayOrder int `json:"display_order,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Album) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case album.FieldID, album.FieldViewCount, album.FieldDownloadCount, album.FieldWidth, album.FieldHeight, album.FieldFileSize, album.FieldDisplayOrder:
			values[i] = new(sql.NullInt64)
		case album.FieldImageURL, album.FieldBigImageURL, album.FieldDownloadURL, album.FieldThumbParam, album.FieldBigParam, album.FieldTags, album.FieldFormat, album.FieldAspectRatio, album.FieldFileHash:
			values[i] = new(sql.NullString)
		case album.FieldDeletedAt, album.FieldCreatedAt, album.FieldUpdatedAt:
			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 Album fields.
func (_m *Album) 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 album.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = uint(value.Int64)
		case album.FieldDeletedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
			} else if value.Valid {
				_m.DeletedAt = new(time.Time)
				*_m.DeletedAt = value.Time
			}
		case album.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 album.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				_m.UpdatedAt = value.Time
			}
		case album.FieldImageURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field image_url", values[i])
			} else if value.Valid {
				_m.ImageURL = value.String
			}
		case album.FieldBigImageURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field big_image_url", values[i])
			} else if value.Valid {
				_m.BigImageURL = value.String
			}
		case album.FieldDownloadURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field download_url", values[i])
			} else if value.Valid {
				_m.DownloadURL = value.String
			}
		case album.FieldThumbParam:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field thumb_param", values[i])
			} else if value.Valid {
				_m.ThumbParam = value.String
			}
		case album.FieldBigParam:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field big_param", values[i])
			} else if value.Valid {
				_m.BigParam = value.String
			}
		case album.FieldTags:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field tags", values[i])
			} else if value.Valid {
				_m.Tags = value.String
			}
		case album.FieldViewCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field view_count", values[i])
			} else if value.Valid {
				_m.ViewCount = int(value.Int64)
			}
		case album.FieldDownloadCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field download_count", values[i])
			} else if value.Valid {
				_m.DownloadCount = int(value.Int64)
			}
		case album.FieldWidth:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field width", values[i])
			} else if value.Valid {
				_m.Width = int(value.Int64)
			}
		case album.FieldHeight:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field height", values[i])
			} else if value.Valid {
				_m.Height = int(value.Int64)
			}
		case album.FieldFileSize:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field file_size", values[i])
			} else if value.Valid {
				_m.FileSize = value.Int64
			}
		case album.FieldFormat:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field format", values[i])
			} else if value.Valid {
				_m.Format = value.String
			}
		case album.FieldAspectRatio:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field aspect_ratio", values[i])
			} else if value.Valid {
				_m.AspectRatio = value.String
			}
		case album.FieldFileHash:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field file_hash", values[i])
			} else if value.Valid {
				_m.FileHash = value.String
			}
		case album.FieldDisplayOrder:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field display_order", values[i])
			} else if value.Valid {
				_m.DisplayOrder = int(value.Int64)
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_m *Album) String() string {
	var builder strings.Builder
	builder.WriteString("Album(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	if v := _m.DeletedAt; v != nil {
		builder.WriteString("deleted_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("image_url=")
	builder.WriteString(_m.ImageURL)
	builder.WriteString(", ")
	builder.WriteString("big_image_url=")
	builder.WriteString(_m.BigImageURL)
	builder.WriteString(", ")
	builder.WriteString("download_url=")
	builder.WriteString(_m.DownloadURL)
	builder.WriteString(", ")
	builder.WriteString("thumb_param=")
	builder.WriteString(_m.ThumbParam)
	builder.WriteString(", ")
	builder.WriteString("big_param=")
	builder.WriteString(_m.BigParam)
	builder.WriteString(", ")
	builder.WriteString("tags=")
	builder.WriteString(_m.Tags)
	builder.WriteString(", ")
	builder.WriteString("view_count=")
	builder.WriteString(fmt.Sprintf("%v", _m.ViewCount))
	builder.WriteString(", ")
	builder.WriteString("download_count=")
	builder.WriteString(fmt.Sprintf("%v", _m.DownloadCount))
	builder.WriteString(", ")
	builder.WriteString("width=")
	builder.WriteString(fmt.Sprintf("%v", _m.Width))
	builder.WriteString(", ")
	builder.WriteString("height=")
	builder.WriteString(fmt.Sprintf("%v", _m.Height))
	builder.WriteString(", ")
	builder.WriteString("file_size=")
	builder.WriteString(fmt.Sprintf("%v", _m.FileSize))
	builder.WriteString(", ")
	builder.WriteString("format=")
	builder.WriteString(_m.Format)
	builder.WriteString(", ")
	builder.WriteString("aspect_ratio=")
	builder.WriteString(_m.AspectRatio)
	builder.WriteString(", ")
	builder.WriteString("file_hash=")
	builder.WriteString(_m.FileHash)
	builder.WriteString(", ")
	builder.WriteString("display_order=")
	builder.WriteString(fmt.Sprintf("%v", _m.DisplayOrder))
	builder.WriteByte(')')
	return builder.String()
}

// Albums is a parsable slice of Album.
type Albums []*Album
