// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/agent"
	"wechat-api/ent/server"
	"wechat-api/ent/wx"

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

// Wx is the model entity for the Wx schema.
type Wx 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"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// 服务器id
	ServerID uint64 `json:"server_id,omitempty"`
	// 端口号
	Port string `json:"port,omitempty"`
	// 进程号
	ProcessID string `json:"process_id,omitempty"`
	// 回调地址
	Callback string `json:"callback,omitempty"`
	// 微信id
	Wxid string `json:"wxid,omitempty"`
	// 微信账号
	Account string `json:"account,omitempty"`
	// 微信昵称
	Nickname string `json:"nickname,omitempty"`
	// 手机号
	Tel string `json:"tel,omitempty"`
	// 微信头像
	HeadBig string `json:"head_big,omitempty"`
	// 机构 ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// 模式ID
	AgentID uint64 `json:"agent_id,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the WxQuery when eager-loading is set.
	Edges        WxEdges `json:"edges"`
	selectValues sql.SelectValues
}

// WxEdges holds the relations/edges for other nodes in the graph.
type WxEdges struct {
	// Server holds the value of the server edge.
	Server *Server `json:"server,omitempty"`
	// Agent holds the value of the agent edge.
	Agent *Agent `json:"agent,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// ServerOrErr returns the Server value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WxEdges) ServerOrErr() (*Server, error) {
	if e.Server != nil {
		return e.Server, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: server.Label}
	}
	return nil, &NotLoadedError{edge: "server"}
}

// AgentOrErr returns the Agent value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WxEdges) AgentOrErr() (*Agent, error) {
	if e.Agent != nil {
		return e.Agent, nil
	} else if e.loadedTypes[1] {
		return nil, &NotFoundError{label: agent.Label}
	}
	return nil, &NotLoadedError{edge: "agent"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Wx) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case wx.FieldID, wx.FieldStatus, wx.FieldServerID, wx.FieldOrganizationID, wx.FieldAgentID:
			values[i] = new(sql.NullInt64)
		case wx.FieldPort, wx.FieldProcessID, wx.FieldCallback, wx.FieldWxid, wx.FieldAccount, wx.FieldNickname, wx.FieldTel, wx.FieldHeadBig:
			values[i] = new(sql.NullString)
		case wx.FieldCreatedAt, wx.FieldUpdatedAt, wx.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 Wx fields.
func (w *Wx) 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 wx.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			w.ID = uint64(value.Int64)
		case wx.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 {
				w.CreatedAt = value.Time
			}
		case wx.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 {
				w.UpdatedAt = value.Time
			}
		case wx.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				w.Status = uint8(value.Int64)
			}
		case wx.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 {
				w.DeletedAt = value.Time
			}
		case wx.FieldServerID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field server_id", values[i])
			} else if value.Valid {
				w.ServerID = uint64(value.Int64)
			}
		case wx.FieldPort:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field port", values[i])
			} else if value.Valid {
				w.Port = value.String
			}
		case wx.FieldProcessID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field process_id", values[i])
			} else if value.Valid {
				w.ProcessID = value.String
			}
		case wx.FieldCallback:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field callback", values[i])
			} else if value.Valid {
				w.Callback = value.String
			}
		case wx.FieldWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wxid", values[i])
			} else if value.Valid {
				w.Wxid = value.String
			}
		case wx.FieldAccount:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field account", values[i])
			} else if value.Valid {
				w.Account = value.String
			}
		case wx.FieldNickname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field nickname", values[i])
			} else if value.Valid {
				w.Nickname = value.String
			}
		case wx.FieldTel:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field tel", values[i])
			} else if value.Valid {
				w.Tel = value.String
			}
		case wx.FieldHeadBig:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field head_big", values[i])
			} else if value.Valid {
				w.HeadBig = value.String
			}
		case wx.FieldOrganizationID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
			} else if value.Valid {
				w.OrganizationID = uint64(value.Int64)
			}
		case wx.FieldAgentID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field agent_id", values[i])
			} else if value.Valid {
				w.AgentID = uint64(value.Int64)
			}
		default:
			w.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryServer queries the "server" edge of the Wx entity.
func (w *Wx) QueryServer() *ServerQuery {
	return NewWxClient(w.config).QueryServer(w)
}

// QueryAgent queries the "agent" edge of the Wx entity.
func (w *Wx) QueryAgent() *AgentQuery {
	return NewWxClient(w.config).QueryAgent(w)
}

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

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

// String implements the fmt.Stringer.
func (w *Wx) String() string {
	var builder strings.Builder
	builder.WriteString("Wx(")
	builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
	builder.WriteString("created_at=")
	builder.WriteString(w.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(w.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", w.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(w.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("server_id=")
	builder.WriteString(fmt.Sprintf("%v", w.ServerID))
	builder.WriteString(", ")
	builder.WriteString("port=")
	builder.WriteString(w.Port)
	builder.WriteString(", ")
	builder.WriteString("process_id=")
	builder.WriteString(w.ProcessID)
	builder.WriteString(", ")
	builder.WriteString("callback=")
	builder.WriteString(w.Callback)
	builder.WriteString(", ")
	builder.WriteString("wxid=")
	builder.WriteString(w.Wxid)
	builder.WriteString(", ")
	builder.WriteString("account=")
	builder.WriteString(w.Account)
	builder.WriteString(", ")
	builder.WriteString("nickname=")
	builder.WriteString(w.Nickname)
	builder.WriteString(", ")
	builder.WriteString("tel=")
	builder.WriteString(w.Tel)
	builder.WriteString(", ")
	builder.WriteString("head_big=")
	builder.WriteString(w.HeadBig)
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("agent_id=")
	builder.WriteString(fmt.Sprintf("%v", w.AgentID))
	builder.WriteByte(')')
	return builder.String()
}

// Wxes is a parsable slice of Wx.
type Wxes []*Wx