// Code generated by ent, DO NOT EDIT.

package ent

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/wpchatroom"

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

// WpChatroom is the model entity for the WpChatroom schema.
type WpChatroom 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
	ChatroomID string `json:"chatroom_id,omitempty"`
	// 群昵称
	Nickname string `json:"nickname,omitempty"`
	// 群主
	Owner string `json:"owner,omitempty"`
	// 群头像
	Avatar string `json:"avatar,omitempty"`
	// 群成员
	MemberList   []string `json:"member_list,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*WpChatroom) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case wpchatroom.FieldMemberList:
			values[i] = new([]byte)
		case wpchatroom.FieldID, wpchatroom.FieldStatus:
			values[i] = new(sql.NullInt64)
		case wpchatroom.FieldWxWxid, wpchatroom.FieldChatroomID, wpchatroom.FieldNickname, wpchatroom.FieldOwner, wpchatroom.FieldAvatar:
			values[i] = new(sql.NullString)
		case wpchatroom.FieldCreatedAt, wpchatroom.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 WpChatroom fields.
func (wc *WpChatroom) 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 wpchatroom.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			wc.ID = uint64(value.Int64)
		case wpchatroom.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 {
				wc.CreatedAt = value.Time
			}
		case wpchatroom.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 {
				wc.UpdatedAt = value.Time
			}
		case wpchatroom.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				wc.Status = uint8(value.Int64)
			}
		case wpchatroom.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 {
				wc.WxWxid = value.String
			}
		case wpchatroom.FieldChatroomID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field chatroom_id", values[i])
			} else if value.Valid {
				wc.ChatroomID = value.String
			}
		case wpchatroom.FieldNickname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field nickname", values[i])
			} else if value.Valid {
				wc.Nickname = value.String
			}
		case wpchatroom.FieldOwner:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field owner", values[i])
			} else if value.Valid {
				wc.Owner = value.String
			}
		case wpchatroom.FieldAvatar:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field avatar", values[i])
			} else if value.Valid {
				wc.Avatar = value.String
			}
		case wpchatroom.FieldMemberList:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field member_list", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &wc.MemberList); err != nil {
					return fmt.Errorf("unmarshal field member_list: %w", err)
				}
			}
		default:
			wc.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (wc *WpChatroom) String() string {
	var builder strings.Builder
	builder.WriteString("WpChatroom(")
	builder.WriteString(fmt.Sprintf("id=%v, ", wc.ID))
	builder.WriteString("created_at=")
	builder.WriteString(wc.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(wc.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", wc.Status))
	builder.WriteString(", ")
	builder.WriteString("wx_wxid=")
	builder.WriteString(wc.WxWxid)
	builder.WriteString(", ")
	builder.WriteString("chatroom_id=")
	builder.WriteString(wc.ChatroomID)
	builder.WriteString(", ")
	builder.WriteString("nickname=")
	builder.WriteString(wc.Nickname)
	builder.WriteString(", ")
	builder.WriteString("owner=")
	builder.WriteString(wc.Owner)
	builder.WriteString(", ")
	builder.WriteString("avatar=")
	builder.WriteString(wc.Avatar)
	builder.WriteString(", ")
	builder.WriteString("member_list=")
	builder.WriteString(fmt.Sprintf("%v", wc.MemberList))
	builder.WriteByte(')')
	return builder.String()
}

// WpChatrooms is a parsable slice of WpChatroom.
type WpChatrooms []*WpChatroom
