// Code generated by ent, DO NOT EDIT.

package ent

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

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

// Msg is the model entity for the Msg schema.
type Msg 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"`
	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
	Status uint8 `json:"status,omitempty"`
	// 发送方微信ID
	Fromwxid string `json:"fromwxid,omitempty"`
	// 接收人微信ID/群ID
	Toid string `json:"toid,omitempty"`
	// 消息类型
	Msgtype int32 `json:"msgtype,omitempty"`
	// 消息
	Msg string `json:"msg,omitempty"`
	// 批次号
	BatchNo string `json:"batch_no,omitempty"`
	// 国家区号
	Cc string `json:"cc,omitempty"`
	// 手机号
	Phone        string `json:"phone,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Msg) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case msg.FieldID, msg.FieldStatus, msg.FieldMsgtype:
			values[i] = new(sql.NullInt64)
		case msg.FieldFromwxid, msg.FieldToid, msg.FieldMsg, msg.FieldBatchNo, msg.FieldCc, msg.FieldPhone:
			values[i] = new(sql.NullString)
		case msg.FieldCreatedAt, msg.FieldUpdatedAt, msg.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 Msg fields.
func (m *Msg) 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 msg.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			m.ID = uint64(value.Int64)
		case msg.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 msg.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 msg.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 = value.Time
			}
		case msg.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				m.Status = uint8(value.Int64)
			}
		case msg.FieldFromwxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field fromwxid", values[i])
			} else if value.Valid {
				m.Fromwxid = value.String
			}
		case msg.FieldToid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field toid", values[i])
			} else if value.Valid {
				m.Toid = value.String
			}
		case msg.FieldMsgtype:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field msgtype", values[i])
			} else if value.Valid {
				m.Msgtype = int32(value.Int64)
			}
		case msg.FieldMsg:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field msg", values[i])
			} else if value.Valid {
				m.Msg = value.String
			}
		case msg.FieldBatchNo:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field batch_no", values[i])
			} else if value.Valid {
				m.BatchNo = value.String
			}
		case msg.FieldCc:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field cc", values[i])
			} else if value.Valid {
				m.Cc = value.String
			}
		case msg.FieldPhone:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field phone", values[i])
			} else if value.Valid {
				m.Phone = value.String
			}
		default:
			m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (m *Msg) String() string {
	var builder strings.Builder
	builder.WriteString("Msg(")
	builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
	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("deleted_at=")
	builder.WriteString(m.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", m.Status))
	builder.WriteString(", ")
	builder.WriteString("fromwxid=")
	builder.WriteString(m.Fromwxid)
	builder.WriteString(", ")
	builder.WriteString("toid=")
	builder.WriteString(m.Toid)
	builder.WriteString(", ")
	builder.WriteString("msgtype=")
	builder.WriteString(fmt.Sprintf("%v", m.Msgtype))
	builder.WriteString(", ")
	builder.WriteString("msg=")
	builder.WriteString(m.Msg)
	builder.WriteString(", ")
	builder.WriteString("batch_no=")
	builder.WriteString(m.BatchNo)
	builder.WriteString(", ")
	builder.WriteString("cc=")
	builder.WriteString(m.Cc)
	builder.WriteString(", ")
	builder.WriteString("phone=")
	builder.WriteString(m.Phone)
	builder.WriteByte(')')
	return builder.String()
}

// Msgs is a parsable slice of Msg.
type Msgs []*Msg
