// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WxCardUser is the model entity for the WxCardUser schema.
type WxCardUser 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"`
	// 微信id
	Wxid string `json:"wxid,omitempty"`
	// 微信号
	Account string `json:"account,omitempty"`
	// 头像
	Avatar string `json:"avatar,omitempty"`
	// 昵称
	Nickname string `json:"nickname,omitempty"`
	// 备注名
	Remark string `json:"remark,omitempty"`
	// 手机号
	Phone string `json:"phone,omitempty"`
	// OpenID
	OpenID string `json:"open_id,omitempty"`
	// UnionID
	UnionID string `json:"union_id,omitempty"`
	// SessionKey
	SessionKey string `json:"session_key,omitempty"`
	// 是否VIP：0-否 1-是
	IsVip        int `json:"is_vip,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*WxCardUser) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case wxcarduser.FieldID, wxcarduser.FieldIsVip:
			values[i] = new(sql.NullInt64)
		case wxcarduser.FieldWxid, wxcarduser.FieldAccount, wxcarduser.FieldAvatar, wxcarduser.FieldNickname, wxcarduser.FieldRemark, wxcarduser.FieldPhone, wxcarduser.FieldOpenID, wxcarduser.FieldUnionID, wxcarduser.FieldSessionKey:
			values[i] = new(sql.NullString)
		case wxcarduser.FieldCreatedAt, wxcarduser.FieldUpdatedAt, wxcarduser.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 WxCardUser fields.
func (wcu *WxCardUser) 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 wxcarduser.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			wcu.ID = uint64(value.Int64)
		case wxcarduser.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 {
				wcu.CreatedAt = value.Time
			}
		case wxcarduser.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 {
				wcu.UpdatedAt = value.Time
			}
		case wxcarduser.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 {
				wcu.DeletedAt = value.Time
			}
		case wxcarduser.FieldWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wxid", values[i])
			} else if value.Valid {
				wcu.Wxid = value.String
			}
		case wxcarduser.FieldAccount:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field account", values[i])
			} else if value.Valid {
				wcu.Account = value.String
			}
		case wxcarduser.FieldAvatar:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field avatar", values[i])
			} else if value.Valid {
				wcu.Avatar = value.String
			}
		case wxcarduser.FieldNickname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field nickname", values[i])
			} else if value.Valid {
				wcu.Nickname = value.String
			}
		case wxcarduser.FieldRemark:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field remark", values[i])
			} else if value.Valid {
				wcu.Remark = value.String
			}
		case wxcarduser.FieldPhone:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field phone", values[i])
			} else if value.Valid {
				wcu.Phone = value.String
			}
		case wxcarduser.FieldOpenID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field open_id", values[i])
			} else if value.Valid {
				wcu.OpenID = value.String
			}
		case wxcarduser.FieldUnionID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field union_id", values[i])
			} else if value.Valid {
				wcu.UnionID = value.String
			}
		case wxcarduser.FieldSessionKey:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field session_key", values[i])
			} else if value.Valid {
				wcu.SessionKey = value.String
			}
		case wxcarduser.FieldIsVip:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field is_vip", values[i])
			} else if value.Valid {
				wcu.IsVip = int(value.Int64)
			}
		default:
			wcu.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (wcu *WxCardUser) String() string {
	var builder strings.Builder
	builder.WriteString("WxCardUser(")
	builder.WriteString(fmt.Sprintf("id=%v, ", wcu.ID))
	builder.WriteString("created_at=")
	builder.WriteString(wcu.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(wcu.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(wcu.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("wxid=")
	builder.WriteString(wcu.Wxid)
	builder.WriteString(", ")
	builder.WriteString("account=")
	builder.WriteString(wcu.Account)
	builder.WriteString(", ")
	builder.WriteString("avatar=")
	builder.WriteString(wcu.Avatar)
	builder.WriteString(", ")
	builder.WriteString("nickname=")
	builder.WriteString(wcu.Nickname)
	builder.WriteString(", ")
	builder.WriteString("remark=")
	builder.WriteString(wcu.Remark)
	builder.WriteString(", ")
	builder.WriteString("phone=")
	builder.WriteString(wcu.Phone)
	builder.WriteString(", ")
	builder.WriteString("open_id=")
	builder.WriteString(wcu.OpenID)
	builder.WriteString(", ")
	builder.WriteString("union_id=")
	builder.WriteString(wcu.UnionID)
	builder.WriteString(", ")
	builder.WriteString("session_key=")
	builder.WriteString(wcu.SessionKey)
	builder.WriteString(", ")
	builder.WriteString("is_vip=")
	builder.WriteString(fmt.Sprintf("%v", wcu.IsVip))
	builder.WriteByte(')')
	return builder.String()
}

// WxCardUsers is a parsable slice of WxCardUser.
type WxCardUsers []*WxCardUser
