// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WpChatroomMember is the model entity for the WpChatroomMember schema.
type WpChatroomMember 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"`
	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
	Status uint8 `json:"status,omitempty"`
	// 所属微信id
	WxWxid string `json:"wx_wxid,omitempty"`
	// 微信id
	Wxid string `json:"wxid,omitempty"`
	// 群昵称
	Nickname string `json:"nickname,omitempty"`
	// 群头像
	Avatar       string `json:"avatar,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*WpChatroomMember) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case wpchatroommember.FieldID, wpchatroommember.FieldStatus:
			values[i] = new(sql.NullInt64)
		case wpchatroommember.FieldWxWxid, wpchatroommember.FieldWxid, wpchatroommember.FieldNickname, wpchatroommember.FieldAvatar:
			values[i] = new(sql.NullString)
		case wpchatroommember.FieldCreatedAt, wpchatroommember.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 WpChatroomMember fields.
func (wcm *WpChatroomMember) 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 wpchatroommember.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			wcm.ID = uint64(value.Int64)
		case wpchatroommember.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 {
				wcm.CreatedAt = value.Time
			}
		case wpchatroommember.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 {
				wcm.UpdatedAt = value.Time
			}
		case wpchatroommember.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				wcm.Status = uint8(value.Int64)
			}
		case wpchatroommember.FieldWxWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wx_wxid", values[i])
			} else if value.Valid {
				wcm.WxWxid = value.String
			}
		case wpchatroommember.FieldWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wxid", values[i])
			} else if value.Valid {
				wcm.Wxid = value.String
			}
		case wpchatroommember.FieldNickname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field nickname", values[i])
			} else if value.Valid {
				wcm.Nickname = value.String
			}
		case wpchatroommember.FieldAvatar:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field avatar", values[i])
			} else if value.Valid {
				wcm.Avatar = value.String
			}
		default:
			wcm.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (wcm *WpChatroomMember) String() string {
	var builder strings.Builder
	builder.WriteString("WpChatroomMember(")
	builder.WriteString(fmt.Sprintf("id=%v, ", wcm.ID))
	builder.WriteString("created_at=")
	builder.WriteString(wcm.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(wcm.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", wcm.Status))
	builder.WriteString(", ")
	builder.WriteString("wx_wxid=")
	builder.WriteString(wcm.WxWxid)
	builder.WriteString(", ")
	builder.WriteString("wxid=")
	builder.WriteString(wcm.Wxid)
	builder.WriteString(", ")
	builder.WriteString("nickname=")
	builder.WriteString(wcm.Nickname)
	builder.WriteString(", ")
	builder.WriteString("avatar=")
	builder.WriteString(wcm.Avatar)
	builder.WriteByte(')')
	return builder.String()
}

// WpChatroomMembers is a parsable slice of WpChatroomMember.
type WpChatroomMembers []*WpChatroomMember
