// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

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

// DocServerGetProject is the model entity for the DocServerGetProject schema.
type DocServerGetProject struct {
	config `json:"-"`
	// ID of the ent.
	// id
	ID int32 `json:"id,omitempty"`
	// 创建项目表id
	ServerProjectID int32 `json:"server_project_id,omitempty"`
	// 获取项目的次数
	CurrNum int32 `json:"curr_num,omitempty"`
	// 状态，0 待获取， 1 获取项目成功
	Status int8 `json:"status,omitempty"`
	// 阿里返回获取项目结果
	AliResult *string `json:"ali_result,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt *time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt    *time.Time `json:"updated_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*DocServerGetProject) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case docservergetproject.FieldID, docservergetproject.FieldServerProjectID, docservergetproject.FieldCurrNum, docservergetproject.FieldStatus:
			values[i] = new(sql.NullInt64)
		case docservergetproject.FieldAliResult:
			values[i] = new(sql.NullString)
		case docservergetproject.FieldCreatedAt, docservergetproject.FieldUpdatedAt:
			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 DocServerGetProject fields.
func (dsgp *DocServerGetProject) 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 docservergetproject.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			dsgp.ID = int32(value.Int64)
		case docservergetproject.FieldServerProjectID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field server_project_id", values[i])
			} else if value.Valid {
				dsgp.ServerProjectID = int32(value.Int64)
			}
		case docservergetproject.FieldCurrNum:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field curr_num", values[i])
			} else if value.Valid {
				dsgp.CurrNum = int32(value.Int64)
			}
		case docservergetproject.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				dsgp.Status = int8(value.Int64)
			}
		case docservergetproject.FieldAliResult:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field ali_result", values[i])
			} else if value.Valid {
				dsgp.AliResult = new(string)
				*dsgp.AliResult = value.String
			}
		case docservergetproject.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 {
				dsgp.CreatedAt = new(time.Time)
				*dsgp.CreatedAt = value.Time
			}
		case docservergetproject.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 {
				dsgp.UpdatedAt = new(time.Time)
				*dsgp.UpdatedAt = value.Time
			}
		default:
			dsgp.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (dsgp *DocServerGetProject) String() string {
	var builder strings.Builder
	builder.WriteString("DocServerGetProject(")
	builder.WriteString(fmt.Sprintf("id=%v, ", dsgp.ID))
	builder.WriteString("server_project_id=")
	builder.WriteString(fmt.Sprintf("%v", dsgp.ServerProjectID))
	builder.WriteString(", ")
	builder.WriteString("curr_num=")
	builder.WriteString(fmt.Sprintf("%v", dsgp.CurrNum))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", dsgp.Status))
	builder.WriteString(", ")
	if v := dsgp.AliResult; v != nil {
		builder.WriteString("ali_result=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := dsgp.CreatedAt; v != nil {
		builder.WriteString("created_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	if v := dsgp.UpdatedAt; v != nil {
		builder.WriteString("updated_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// DocServerGetProjects is a parsable slice of DocServerGetProject.
type DocServerGetProjects []*DocServerGetProject
