// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

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

// DocServerCallback is the model entity for the DocServerCallback schema.
type DocServerCallback struct {
	config `json:"-"`
	// ID of the ent.
	// id
	ID int32 `json:"id,omitempty"`
	// 创建项目表id
	ServerProjectID int32 `json:"server_project_id,omitempty"`
	// 业务回调地址
	CallbackURL string `json:"callback_url,omitempty"`
	// 业务回调参数
	CallbackData string `json:"callback_data,omitempty"`
	// 业务需要的回调类型，1 回调地址，2 直接改表
	CallbackType int8 `json:"callback_type,omitempty"`
	// 状态 0 待执行  1 执行成功....
	Status int8 `json:"status,omitempty"`
	// 执行次数
	CurrNum int32 `json:"curr_num,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"`
	// DeletedAt holds the value of the "deleted_at" field.
	DeletedAt    *time.Time `json:"deleted_at,omitempty"`
	selectValues sql.SelectValues
}

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

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

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

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

// String implements the fmt.Stringer.
func (dsc *DocServerCallback) String() string {
	var builder strings.Builder
	builder.WriteString("DocServerCallback(")
	builder.WriteString(fmt.Sprintf("id=%v, ", dsc.ID))
	builder.WriteString("server_project_id=")
	builder.WriteString(fmt.Sprintf("%v", dsc.ServerProjectID))
	builder.WriteString(", ")
	builder.WriteString("callback_url=")
	builder.WriteString(dsc.CallbackURL)
	builder.WriteString(", ")
	builder.WriteString("callback_data=")
	builder.WriteString(dsc.CallbackData)
	builder.WriteString(", ")
	builder.WriteString("callback_type=")
	builder.WriteString(fmt.Sprintf("%v", dsc.CallbackType))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", dsc.Status))
	builder.WriteString(", ")
	builder.WriteString("curr_num=")
	builder.WriteString(fmt.Sprintf("%v", dsc.CurrNum))
	builder.WriteString(", ")
	if v := dsc.CreatedAt; v != nil {
		builder.WriteString("created_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	if v := dsc.UpdatedAt; v != nil {
		builder.WriteString("updated_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	if v := dsc.DeletedAt; v != nil {
		builder.WriteString("deleted_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// DocServerCallbacks is a parsable slice of DocServerCallback.
type DocServerCallbacks []*DocServerCallback
