// Code generated by ent, DO NOT EDIT.

package serversitemicros

import (
	"convert-server/domain/entity/serversitemicros/docserverapp"
	"fmt"
	"strings"
	"time"

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

// DocServerApp is the model entity for the DocServerApp schema.
type DocServerApp struct {
	config `json:"-"`
	// ID of the ent.
	// 业务id
	ID int32 `json:"id,omitempty"`
	// 密钥
	Application string `json:"application,omitempty"`
	// 名称
	Name string `json:"name,omitempty"`
	// 创建时间
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*DocServerApp) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case docserverapp.FieldID:
			values[i] = new(sql.NullInt64)
		case docserverapp.FieldApplication, docserverapp.FieldName:
			values[i] = new(sql.NullString)
		case docserverapp.FieldCreatedAt:
			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 DocServerApp fields.
func (dsa *DocServerApp) 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 docserverapp.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			dsa.ID = int32(value.Int64)
		case docserverapp.FieldApplication:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field application", values[i])
			} else if value.Valid {
				dsa.Application = value.String
			}
		case docserverapp.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				dsa.Name = value.String
			}
		case docserverapp.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 {
				dsa.CreatedAt = new(time.Time)
				*dsa.CreatedAt = value.Time
			}
		default:
			dsa.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (dsa *DocServerApp) String() string {
	var builder strings.Builder
	builder.WriteString("DocServerApp(")
	builder.WriteString(fmt.Sprintf("id=%v, ", dsa.ID))
	builder.WriteString("application=")
	builder.WriteString(dsa.Application)
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(dsa.Name)
	builder.WriteString(", ")
	if v := dsa.CreatedAt; v != nil {
		builder.WriteString("created_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// DocServerApps is a parsable slice of DocServerApp.
type DocServerApps []*DocServerApp
