// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"galileo/ent/job"
	"strings"
	"time"

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

// Job is the model entity for the Job schema.
type Job struct {
	config `json:"-"`
	// ID of the ent.
	// Job ID
	ID int64 `json:"id,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"created_at,omitempty"`
	// 执行人
	CreatedBy uint32 `json:"created_by,omitempty"`
	// Payload
	Payload []byte `json:"payload,omitempty"`
	// 任务类型
	Type string `json:"type,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// 当前的工作节点, 存储格式为IP地址
	Worker uint32 `json:"worker,omitempty"`
	// 删除时间
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// 删除操作执行人
	DeletedBy uint32 `json:"deleted_by,omitempty"`
	// Entry ID
	EntryID string `json:"entry_id,omitempty"`
	// 配置信息
	Config []byte `json:"config,omitempty"`
	// 关联的任务ID
	TaskID int64 `json:"task_id,omitempty"`
	// Job 执行情况
	Active bool `json:"active,omitempty"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Job) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case job.FieldPayload, job.FieldConfig:
			values[i] = new([]byte)
		case job.FieldActive:
			values[i] = new(sql.NullBool)
		case job.FieldID, job.FieldCreatedBy, job.FieldWorker, job.FieldDeletedBy, job.FieldTaskID:
			values[i] = new(sql.NullInt64)
		case job.FieldType, job.FieldEntryID:
			values[i] = new(sql.NullString)
		case job.FieldCreatedAt, job.FieldUpdatedAt, job.FieldDeletedAt:
			values[i] = new(sql.NullTime)
		default:
			return nil, fmt.Errorf("unexpected column %q for type Job", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Job fields.
func (j *Job) 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 job.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			j.ID = int64(value.Int64)
		case job.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 {
				j.CreatedAt = value.Time
			}
		case job.FieldCreatedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field created_by", values[i])
			} else if value.Valid {
				j.CreatedBy = uint32(value.Int64)
			}
		case job.FieldPayload:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field payload", values[i])
			} else if value != nil {
				j.Payload = *value
			}
		case job.FieldType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				j.Type = value.String
			}
		case job.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 {
				j.UpdatedAt = value.Time
			}
		case job.FieldWorker:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field worker", values[i])
			} else if value.Valid {
				j.Worker = uint32(value.Int64)
			}
		case job.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 {
				j.DeletedAt = value.Time
			}
		case job.FieldDeletedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_by", values[i])
			} else if value.Valid {
				j.DeletedBy = uint32(value.Int64)
			}
		case job.FieldEntryID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field entry_id", values[i])
			} else if value.Valid {
				j.EntryID = value.String
			}
		case job.FieldConfig:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field config", values[i])
			} else if value != nil {
				j.Config = *value
			}
		case job.FieldTaskID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field task_id", values[i])
			} else if value.Valid {
				j.TaskID = value.Int64
			}
		case job.FieldActive:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field active", values[i])
			} else if value.Valid {
				j.Active = value.Bool
			}
		}
	}
	return nil
}

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

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

// String implements the fmt.Stringer.
func (j *Job) String() string {
	var builder strings.Builder
	builder.WriteString("Job(")
	builder.WriteString(fmt.Sprintf("id=%v, ", j.ID))
	builder.WriteString("created_at=")
	builder.WriteString(j.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("created_by=")
	builder.WriteString(fmt.Sprintf("%v", j.CreatedBy))
	builder.WriteString(", ")
	builder.WriteString("payload=")
	builder.WriteString(fmt.Sprintf("%v", j.Payload))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(j.Type)
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(j.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("worker=")
	builder.WriteString(fmt.Sprintf("%v", j.Worker))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(j.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_by=")
	builder.WriteString(fmt.Sprintf("%v", j.DeletedBy))
	builder.WriteString(", ")
	builder.WriteString("entry_id=")
	builder.WriteString(j.EntryID)
	builder.WriteString(", ")
	builder.WriteString("config=")
	builder.WriteString(fmt.Sprintf("%v", j.Config))
	builder.WriteString(", ")
	builder.WriteString("task_id=")
	builder.WriteString(fmt.Sprintf("%v", j.TaskID))
	builder.WriteString(", ")
	builder.WriteString("active=")
	builder.WriteString(fmt.Sprintf("%v", j.Active))
	builder.WriteByte(')')
	return builder.String()
}

// Jobs is a parsable slice of Job.
type Jobs []*Job
