// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/aliyunavatar"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

// AliyunAvatar is the model entity for the AliyunAvatar schema.
type AliyunAvatar struct {
	config `json:"-"`
	// ID of the ent.
	ID uint64 `json:"id,omitempty"`
	// Create Time | 创建日期
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Update Time | 修改日期
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// user_id | wx_card_user_id
	UserID uint64 `json:"user_id,omitempty"`
	// biz_id | BizId
	BizID string `json:"biz_id,omitempty"`
	// access_key_id | AccessKeyId
	AccessKeyID string `json:"access_key_id,omitempty"`
	// access_key_secret | AccessKeySecret
	AccessKeySecret string `json:"access_key_secret,omitempty"`
	// app_id | AppId
	AppID string `json:"app_id,omitempty"`
	// tenant_id | TenantId
	TenantID uint64 `json:"tenant_id,omitempty"`
	// response | 阿里云avatar响应
	Response string `json:"response,omitempty"`
	// token | Token
	Token string `json:"token,omitempty"`
	// session_id | SessionId
	SessionID    string `json:"session_id,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*AliyunAvatar) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case aliyunavatar.FieldID, aliyunavatar.FieldUserID, aliyunavatar.FieldTenantID:
			values[i] = new(sql.NullInt64)
		case aliyunavatar.FieldBizID, aliyunavatar.FieldAccessKeyID, aliyunavatar.FieldAccessKeySecret, aliyunavatar.FieldAppID, aliyunavatar.FieldResponse, aliyunavatar.FieldToken, aliyunavatar.FieldSessionID:
			values[i] = new(sql.NullString)
		case aliyunavatar.FieldCreatedAt, aliyunavatar.FieldUpdatedAt, aliyunavatar.FieldDeletedAt:
			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 AliyunAvatar fields.
func (aa *AliyunAvatar) 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 aliyunavatar.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			aa.ID = uint64(value.Int64)
		case aliyunavatar.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 {
				aa.CreatedAt = value.Time
			}
		case aliyunavatar.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 {
				aa.UpdatedAt = value.Time
			}
		case aliyunavatar.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 {
				aa.DeletedAt = value.Time
			}
		case aliyunavatar.FieldUserID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field user_id", values[i])
			} else if value.Valid {
				aa.UserID = uint64(value.Int64)
			}
		case aliyunavatar.FieldBizID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field biz_id", values[i])
			} else if value.Valid {
				aa.BizID = value.String
			}
		case aliyunavatar.FieldAccessKeyID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field access_key_id", values[i])
			} else if value.Valid {
				aa.AccessKeyID = value.String
			}
		case aliyunavatar.FieldAccessKeySecret:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field access_key_secret", values[i])
			} else if value.Valid {
				aa.AccessKeySecret = value.String
			}
		case aliyunavatar.FieldAppID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field app_id", values[i])
			} else if value.Valid {
				aa.AppID = value.String
			}
		case aliyunavatar.FieldTenantID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field tenant_id", values[i])
			} else if value.Valid {
				aa.TenantID = uint64(value.Int64)
			}
		case aliyunavatar.FieldResponse:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field response", values[i])
			} else if value.Valid {
				aa.Response = value.String
			}
		case aliyunavatar.FieldToken:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field token", values[i])
			} else if value.Valid {
				aa.Token = value.String
			}
		case aliyunavatar.FieldSessionID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field session_id", values[i])
			} else if value.Valid {
				aa.SessionID = value.String
			}
		default:
			aa.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (aa *AliyunAvatar) String() string {
	var builder strings.Builder
	builder.WriteString("AliyunAvatar(")
	builder.WriteString(fmt.Sprintf("id=%v, ", aa.ID))
	builder.WriteString("created_at=")
	builder.WriteString(aa.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(aa.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(aa.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", aa.UserID))
	builder.WriteString(", ")
	builder.WriteString("biz_id=")
	builder.WriteString(aa.BizID)
	builder.WriteString(", ")
	builder.WriteString("access_key_id=")
	builder.WriteString(aa.AccessKeyID)
	builder.WriteString(", ")
	builder.WriteString("access_key_secret=")
	builder.WriteString(aa.AccessKeySecret)
	builder.WriteString(", ")
	builder.WriteString("app_id=")
	builder.WriteString(aa.AppID)
	builder.WriteString(", ")
	builder.WriteString("tenant_id=")
	builder.WriteString(fmt.Sprintf("%v", aa.TenantID))
	builder.WriteString(", ")
	builder.WriteString("response=")
	builder.WriteString(aa.Response)
	builder.WriteString(", ")
	builder.WriteString("token=")
	builder.WriteString(aa.Token)
	builder.WriteString(", ")
	builder.WriteString("session_id=")
	builder.WriteString(aa.SessionID)
	builder.WriteByte(')')
	return builder.String()
}

// AliyunAvatars is a parsable slice of AliyunAvatar.
type AliyunAvatars []*AliyunAvatar
