// Code generated by ent, DO NOT EDIT.

package ent

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

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

// Server is the model entity for the Server schema.
type Server 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"`
	// 名称
	Name string `json:"name,omitempty"`
	// 公网ip
	PublicIP string `json:"public_ip,omitempty"`
	// 内网ip
	PrivateIP string `json:"private_ip,omitempty"`
	// 管理端口
	AdminPort string `json:"admin_port,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the ServerQuery when eager-loading is set.
	Edges        ServerEdges `json:"edges"`
	selectValues sql.SelectValues
}

// ServerEdges holds the relations/edges for other nodes in the graph.
type ServerEdges struct {
	// Wxs holds the value of the wxs edge.
	Wxs []*Wx `json:"wxs,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
}

// WxsOrErr returns the Wxs value or an error if the edge
// was not loaded in eager-loading.
func (e ServerEdges) WxsOrErr() ([]*Wx, error) {
	if e.loadedTypes[0] {
		return e.Wxs, nil
	}
	return nil, &NotLoadedError{edge: "wxs"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Server) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case server.FieldID, server.FieldStatus:
			values[i] = new(sql.NullInt64)
		case server.FieldName, server.FieldPublicIP, server.FieldPrivateIP, server.FieldAdminPort:
			values[i] = new(sql.NullString)
		case server.FieldCreatedAt, server.FieldUpdatedAt, server.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 Server fields.
func (s *Server) 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 server.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			s.ID = uint64(value.Int64)
		case server.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 {
				s.CreatedAt = value.Time
			}
		case server.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 {
				s.UpdatedAt = value.Time
			}
		case server.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				s.Status = uint8(value.Int64)
			}
		case server.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 {
				s.DeletedAt = value.Time
			}
		case server.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				s.Name = value.String
			}
		case server.FieldPublicIP:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field public_ip", values[i])
			} else if value.Valid {
				s.PublicIP = value.String
			}
		case server.FieldPrivateIP:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field private_ip", values[i])
			} else if value.Valid {
				s.PrivateIP = value.String
			}
		case server.FieldAdminPort:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field admin_port", values[i])
			} else if value.Valid {
				s.AdminPort = value.String
			}
		default:
			s.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryWxs queries the "wxs" edge of the Server entity.
func (s *Server) QueryWxs() *WxQuery {
	return NewServerClient(s.config).QueryWxs(s)
}

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

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

// String implements the fmt.Stringer.
func (s *Server) String() string {
	var builder strings.Builder
	builder.WriteString("Server(")
	builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
	builder.WriteString("created_at=")
	builder.WriteString(s.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(s.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", s.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(s.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(s.Name)
	builder.WriteString(", ")
	builder.WriteString("public_ip=")
	builder.WriteString(s.PublicIP)
	builder.WriteString(", ")
	builder.WriteString("private_ip=")
	builder.WriteString(s.PrivateIP)
	builder.WriteString(", ")
	builder.WriteString("admin_port=")
	builder.WriteString(s.AdminPort)
	builder.WriteByte(')')
	return builder.String()
}

// Servers is a parsable slice of Server.
type Servers []*Server
