// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

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

// DocServerProject is the model entity for the DocServerProject schema.
type DocServerProject struct {
	config `json:"-"`
	// ID of the ent.
	// id
	ID int32 `json:"id,omitempty"`
	// 项目名称
	ProjectName string `json:"project_name,omitempty"`
	// 来源类型
	SourceType string `json:"source_type,omitempty"`
	// 文件类型
	TargetType string `json:"target_type,omitempty"`
	// 原url
	SourceURL *string `json:"source_url,omitempty"`
	// 目标url
	TargetURL *string `json:"target_url,omitempty"`
	// 返回的文件转换任务id
	TaskID string `json:"task_id,omitempty"`
	// 应用id
	AppID int32 `json:"app_id,omitempty"`
	// 状态
	Status int32 `json:"status,omitempty"`
	// 创建时间
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*DocServerProject) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case docserverproject.FieldID, docserverproject.FieldAppID, docserverproject.FieldStatus:
			values[i] = new(sql.NullInt64)
		case docserverproject.FieldProjectName, docserverproject.FieldSourceType, docserverproject.FieldTargetType, docserverproject.FieldSourceURL, docserverproject.FieldTargetURL, docserverproject.FieldTaskID:
			values[i] = new(sql.NullString)
		case docserverproject.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 DocServerProject fields.
func (dsp *DocServerProject) 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 docserverproject.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			dsp.ID = int32(value.Int64)
		case docserverproject.FieldProjectName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field project_name", values[i])
			} else if value.Valid {
				dsp.ProjectName = value.String
			}
		case docserverproject.FieldSourceType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field source_type", values[i])
			} else if value.Valid {
				dsp.SourceType = value.String
			}
		case docserverproject.FieldTargetType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field target_type", values[i])
			} else if value.Valid {
				dsp.TargetType = value.String
			}
		case docserverproject.FieldSourceURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field source_url", values[i])
			} else if value.Valid {
				dsp.SourceURL = new(string)
				*dsp.SourceURL = value.String
			}
		case docserverproject.FieldTargetURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field target_url", values[i])
			} else if value.Valid {
				dsp.TargetURL = new(string)
				*dsp.TargetURL = value.String
			}
		case docserverproject.FieldTaskID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field task_id", values[i])
			} else if value.Valid {
				dsp.TaskID = value.String
			}
		case docserverproject.FieldAppID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field app_id", values[i])
			} else if value.Valid {
				dsp.AppID = int32(value.Int64)
			}
		case docserverproject.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				dsp.Status = int32(value.Int64)
			}
		case docserverproject.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 {
				dsp.CreatedAt = new(time.Time)
				*dsp.CreatedAt = value.Time
			}
		default:
			dsp.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (dsp *DocServerProject) String() string {
	var builder strings.Builder
	builder.WriteString("DocServerProject(")
	builder.WriteString(fmt.Sprintf("id=%v, ", dsp.ID))
	builder.WriteString("project_name=")
	builder.WriteString(dsp.ProjectName)
	builder.WriteString(", ")
	builder.WriteString("source_type=")
	builder.WriteString(dsp.SourceType)
	builder.WriteString(", ")
	builder.WriteString("target_type=")
	builder.WriteString(dsp.TargetType)
	builder.WriteString(", ")
	if v := dsp.SourceURL; v != nil {
		builder.WriteString("source_url=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := dsp.TargetURL; v != nil {
		builder.WriteString("target_url=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("task_id=")
	builder.WriteString(dsp.TaskID)
	builder.WriteString(", ")
	builder.WriteString("app_id=")
	builder.WriteString(fmt.Sprintf("%v", dsp.AppID))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", dsp.Status))
	builder.WriteString(", ")
	if v := dsp.CreatedAt; v != nil {
		builder.WriteString("created_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// DocServerProjects is a parsable slice of DocServerProject.
type DocServerProjects []*DocServerProject
