// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/employee"
	"wechat-api/ent/workexperience"

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

// WorkExperience is the model entity for the WorkExperience schema.
type WorkExperience struct {
	config `json:"-"`
	// ID of the ent.
	ID uint64 `json:"id,omitempty"`
	// Create Time | 创建日期
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Update Time | 修改日期
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// employee_id | 员工ID
	EmployeeID uint64 `json:"employee_id,omitempty"`
	// start_date | 开始时间
	StartDate time.Time `json:"start_date,omitempty"`
	// end_date | 结束时间
	EndDate time.Time `json:"end_date,omitempty"`
	// company | 公司名
	Company string `json:"company,omitempty"`
	// experience | 工作内容
	Experience string `json:"experience,omitempty"`
	// organization_id | 租户ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the WorkExperienceQuery when eager-loading is set.
	Edges        WorkExperienceEdges `json:"edges"`
	selectValues sql.SelectValues
}

// WorkExperienceEdges holds the relations/edges for other nodes in the graph.
type WorkExperienceEdges struct {
	// Employee holds the value of the employee edge.
	Employee *Employee `json:"employee,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
}

// EmployeeOrErr returns the Employee value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WorkExperienceEdges) EmployeeOrErr() (*Employee, error) {
	if e.Employee != nil {
		return e.Employee, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: employee.Label}
	}
	return nil, &NotLoadedError{edge: "employee"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*WorkExperience) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case workexperience.FieldID, workexperience.FieldEmployeeID, workexperience.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case workexperience.FieldCompany, workexperience.FieldExperience:
			values[i] = new(sql.NullString)
		case workexperience.FieldCreatedAt, workexperience.FieldUpdatedAt, workexperience.FieldDeletedAt, workexperience.FieldStartDate, workexperience.FieldEndDate:
			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 WorkExperience fields.
func (we *WorkExperience) 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 workexperience.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			we.ID = uint64(value.Int64)
		case workexperience.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 {
				we.CreatedAt = value.Time
			}
		case workexperience.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 {
				we.UpdatedAt = value.Time
			}
		case workexperience.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 {
				we.DeletedAt = value.Time
			}
		case workexperience.FieldEmployeeID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field employee_id", values[i])
			} else if value.Valid {
				we.EmployeeID = uint64(value.Int64)
			}
		case workexperience.FieldStartDate:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field start_date", values[i])
			} else if value.Valid {
				we.StartDate = value.Time
			}
		case workexperience.FieldEndDate:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field end_date", values[i])
			} else if value.Valid {
				we.EndDate = value.Time
			}
		case workexperience.FieldCompany:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field company", values[i])
			} else if value.Valid {
				we.Company = value.String
			}
		case workexperience.FieldExperience:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field experience", values[i])
			} else if value.Valid {
				we.Experience = value.String
			}
		case workexperience.FieldOrganizationID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
			} else if value.Valid {
				we.OrganizationID = uint64(value.Int64)
			}
		default:
			we.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryEmployee queries the "employee" edge of the WorkExperience entity.
func (we *WorkExperience) QueryEmployee() *EmployeeQuery {
	return NewWorkExperienceClient(we.config).QueryEmployee(we)
}

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

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

// String implements the fmt.Stringer.
func (we *WorkExperience) String() string {
	var builder strings.Builder
	builder.WriteString("WorkExperience(")
	builder.WriteString(fmt.Sprintf("id=%v, ", we.ID))
	builder.WriteString("created_at=")
	builder.WriteString(we.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(we.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(we.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("employee_id=")
	builder.WriteString(fmt.Sprintf("%v", we.EmployeeID))
	builder.WriteString(", ")
	builder.WriteString("start_date=")
	builder.WriteString(we.StartDate.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("end_date=")
	builder.WriteString(we.EndDate.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("company=")
	builder.WriteString(we.Company)
	builder.WriteString(", ")
	builder.WriteString("experience=")
	builder.WriteString(we.Experience)
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", we.OrganizationID))
	builder.WriteByte(')')
	return builder.String()
}

// WorkExperiences is a parsable slice of WorkExperience.
type WorkExperiences []*WorkExperience
