// Code generated by ent, DO NOT EDIT.

package ent

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

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

// Xunji is the model entity for the Xunji schema.
type Xunji 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"`
	// AppKey
	AppKey string `json:"app_key,omitempty"`
	// AppSecret
	AppSecret string `json:"app_secret,omitempty"`
	// Token
	Token string `json:"token,omitempty"`
	// 加密key
	EncodingKey string `json:"encoding_key,omitempty"`
	// 角色ID
	AgentID uint64 `json:"agent_id,omitempty"`
	// organization_id | 租户ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// 微信ID
	Wxid string `json:"wxid,omitempty"`
	// 大模型服务地址
	APIBase string `json:"api_base,omitempty"`
	// 大模型服务密钥
	APIKey       string `json:"api_key,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Xunji) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case xunji.FieldID, xunji.FieldStatus, xunji.FieldAgentID, xunji.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case xunji.FieldAppKey, xunji.FieldAppSecret, xunji.FieldToken, xunji.FieldEncodingKey, xunji.FieldWxid, xunji.FieldAPIBase, xunji.FieldAPIKey:
			values[i] = new(sql.NullString)
		case xunji.FieldCreatedAt, xunji.FieldUpdatedAt, xunji.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 Xunji fields.
func (x *Xunji) 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 xunji.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			x.ID = uint64(value.Int64)
		case xunji.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 {
				x.CreatedAt = value.Time
			}
		case xunji.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 {
				x.UpdatedAt = value.Time
			}
		case xunji.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				x.Status = uint8(value.Int64)
			}
		case xunji.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 {
				x.DeletedAt = value.Time
			}
		case xunji.FieldAppKey:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field app_key", values[i])
			} else if value.Valid {
				x.AppKey = value.String
			}
		case xunji.FieldAppSecret:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field app_secret", values[i])
			} else if value.Valid {
				x.AppSecret = value.String
			}
		case xunji.FieldToken:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field token", values[i])
			} else if value.Valid {
				x.Token = value.String
			}
		case xunji.FieldEncodingKey:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field encoding_key", values[i])
			} else if value.Valid {
				x.EncodingKey = value.String
			}
		case xunji.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 {
				x.AgentID = uint64(value.Int64)
			}
		case xunji.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 {
				x.OrganizationID = uint64(value.Int64)
			}
		case xunji.FieldWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wxid", values[i])
			} else if value.Valid {
				x.Wxid = value.String
			}
		case xunji.FieldAPIBase:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field api_base", values[i])
			} else if value.Valid {
				x.APIBase = value.String
			}
		case xunji.FieldAPIKey:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field api_key", values[i])
			} else if value.Valid {
				x.APIKey = value.String
			}
		default:
			x.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (x *Xunji) String() string {
	var builder strings.Builder
	builder.WriteString("Xunji(")
	builder.WriteString(fmt.Sprintf("id=%v, ", x.ID))
	builder.WriteString("created_at=")
	builder.WriteString(x.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(x.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", x.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(x.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("app_key=")
	builder.WriteString(x.AppKey)
	builder.WriteString(", ")
	builder.WriteString("app_secret=")
	builder.WriteString(x.AppSecret)
	builder.WriteString(", ")
	builder.WriteString("token=")
	builder.WriteString(x.Token)
	builder.WriteString(", ")
	builder.WriteString("encoding_key=")
	builder.WriteString(x.EncodingKey)
	builder.WriteString(", ")
	builder.WriteString("agent_id=")
	builder.WriteString(fmt.Sprintf("%v", x.AgentID))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", x.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("wxid=")
	builder.WriteString(x.Wxid)
	builder.WriteString(", ")
	builder.WriteString("api_base=")
	builder.WriteString(x.APIBase)
	builder.WriteString(", ")
	builder.WriteString("api_key=")
	builder.WriteString(x.APIKey)
	builder.WriteByte(')')
	return builder.String()
}

// Xunjis is a parsable slice of Xunji.
type Xunjis []*Xunji
