// Code generated by ent, DO NOT EDIT.

package ent

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

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

// Employee is the model entity for the Employee schema.
type Employee 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"`
	// title | 标题
	Title string `json:"title,omitempty"`
	// avatar | 头像
	Avatar string `json:"avatar,omitempty"`
	// tags | 个人标签
	Tags string `json:"tags,omitempty"`
	// hire_count | 被雇佣次数
	HireCount int `json:"hire_count,omitempty"`
	// service_count | 已服务次数
	ServiceCount int `json:"service_count,omitempty"`
	// achievement_count | 业绩单数
	AchievementCount int `json:"achievement_count,omitempty"`
	// intro | 个人介绍
	Intro string `json:"intro,omitempty"`
	// estimate | 自我评价
	Estimate string `json:"estimate,omitempty"`
	// skill | 技能卡
	Skill string `json:"skill,omitempty"`
	// ability_type | 能力类型
	AbilityType string `json:"ability_type,omitempty"`
	// scene | 使用场景
	Scene string `json:"scene,omitempty"`
	// switch_in | 支持介入
	SwitchIn string `json:"switch_in,omitempty"`
	// video_url | 视频地址
	VideoURL string `json:"video_url,omitempty"`
	// organization_id | 租户ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// category_id | 分类ID
	CategoryID uint64 `json:"category_id,omitempty"`
	// api_base
	APIBase string `json:"api_base,omitempty"`
	// api_key
	APIKey string `json:"api_key,omitempty"`
	// AI信息
	AiInfo string `json:"ai_info,omitempty"`
	// 是否VIP：0-否 1-是
	IsVip int `json:"is_vip,omitempty"`
	// 聊天URL
	ChatURL string `json:"chat_url,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the EmployeeQuery when eager-loading is set.
	Edges        EmployeeEdges `json:"edges"`
	selectValues sql.SelectValues
}

// EmployeeEdges holds the relations/edges for other nodes in the graph.
type EmployeeEdges struct {
	// EmWorkExperiences holds the value of the em_work_experiences edge.
	EmWorkExperiences []*WorkExperience `json:"em_work_experiences,omitempty"`
	// EmTutorial holds the value of the em_tutorial edge.
	EmTutorial []*Tutorial `json:"em_tutorial,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// EmWorkExperiencesOrErr returns the EmWorkExperiences value or an error if the edge
// was not loaded in eager-loading.
func (e EmployeeEdges) EmWorkExperiencesOrErr() ([]*WorkExperience, error) {
	if e.loadedTypes[0] {
		return e.EmWorkExperiences, nil
	}
	return nil, &NotLoadedError{edge: "em_work_experiences"}
}

// EmTutorialOrErr returns the EmTutorial value or an error if the edge
// was not loaded in eager-loading.
func (e EmployeeEdges) EmTutorialOrErr() ([]*Tutorial, error) {
	if e.loadedTypes[1] {
		return e.EmTutorial, nil
	}
	return nil, &NotLoadedError{edge: "em_tutorial"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Employee) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case employee.FieldID, employee.FieldHireCount, employee.FieldServiceCount, employee.FieldAchievementCount, employee.FieldOrganizationID, employee.FieldCategoryID, employee.FieldIsVip:
			values[i] = new(sql.NullInt64)
		case employee.FieldTitle, employee.FieldAvatar, employee.FieldTags, employee.FieldIntro, employee.FieldEstimate, employee.FieldSkill, employee.FieldAbilityType, employee.FieldScene, employee.FieldSwitchIn, employee.FieldVideoURL, employee.FieldAPIBase, employee.FieldAPIKey, employee.FieldAiInfo, employee.FieldChatURL:
			values[i] = new(sql.NullString)
		case employee.FieldCreatedAt, employee.FieldUpdatedAt, employee.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 Employee fields.
func (e *Employee) 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 employee.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			e.ID = uint64(value.Int64)
		case employee.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 {
				e.CreatedAt = value.Time
			}
		case employee.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 {
				e.UpdatedAt = value.Time
			}
		case employee.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 {
				e.DeletedAt = value.Time
			}
		case employee.FieldTitle:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field title", values[i])
			} else if value.Valid {
				e.Title = value.String
			}
		case employee.FieldAvatar:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field avatar", values[i])
			} else if value.Valid {
				e.Avatar = value.String
			}
		case employee.FieldTags:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field tags", values[i])
			} else if value.Valid {
				e.Tags = value.String
			}
		case employee.FieldHireCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field hire_count", values[i])
			} else if value.Valid {
				e.HireCount = int(value.Int64)
			}
		case employee.FieldServiceCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field service_count", values[i])
			} else if value.Valid {
				e.ServiceCount = int(value.Int64)
			}
		case employee.FieldAchievementCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field achievement_count", values[i])
			} else if value.Valid {
				e.AchievementCount = int(value.Int64)
			}
		case employee.FieldIntro:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field intro", values[i])
			} else if value.Valid {
				e.Intro = value.String
			}
		case employee.FieldEstimate:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field estimate", values[i])
			} else if value.Valid {
				e.Estimate = value.String
			}
		case employee.FieldSkill:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field skill", values[i])
			} else if value.Valid {
				e.Skill = value.String
			}
		case employee.FieldAbilityType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field ability_type", values[i])
			} else if value.Valid {
				e.AbilityType = value.String
			}
		case employee.FieldScene:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field scene", values[i])
			} else if value.Valid {
				e.Scene = value.String
			}
		case employee.FieldSwitchIn:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field switch_in", values[i])
			} else if value.Valid {
				e.SwitchIn = value.String
			}
		case employee.FieldVideoURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field video_url", values[i])
			} else if value.Valid {
				e.VideoURL = value.String
			}
		case employee.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 {
				e.OrganizationID = uint64(value.Int64)
			}
		case employee.FieldCategoryID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field category_id", values[i])
			} else if value.Valid {
				e.CategoryID = uint64(value.Int64)
			}
		case employee.FieldAPIBase:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field api_base", values[i])
			} else if value.Valid {
				e.APIBase = value.String
			}
		case employee.FieldAPIKey:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field api_key", values[i])
			} else if value.Valid {
				e.APIKey = value.String
			}
		case employee.FieldAiInfo:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field ai_info", values[i])
			} else if value.Valid {
				e.AiInfo = value.String
			}
		case employee.FieldIsVip:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field is_vip", values[i])
			} else if value.Valid {
				e.IsVip = int(value.Int64)
			}
		case employee.FieldChatURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field chat_url", values[i])
			} else if value.Valid {
				e.ChatURL = value.String
			}
		default:
			e.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryEmWorkExperiences queries the "em_work_experiences" edge of the Employee entity.
func (e *Employee) QueryEmWorkExperiences() *WorkExperienceQuery {
	return NewEmployeeClient(e.config).QueryEmWorkExperiences(e)
}

// QueryEmTutorial queries the "em_tutorial" edge of the Employee entity.
func (e *Employee) QueryEmTutorial() *TutorialQuery {
	return NewEmployeeClient(e.config).QueryEmTutorial(e)
}

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

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

// String implements the fmt.Stringer.
func (e *Employee) String() string {
	var builder strings.Builder
	builder.WriteString("Employee(")
	builder.WriteString(fmt.Sprintf("id=%v, ", e.ID))
	builder.WriteString("created_at=")
	builder.WriteString(e.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(e.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(e.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("title=")
	builder.WriteString(e.Title)
	builder.WriteString(", ")
	builder.WriteString("avatar=")
	builder.WriteString(e.Avatar)
	builder.WriteString(", ")
	builder.WriteString("tags=")
	builder.WriteString(e.Tags)
	builder.WriteString(", ")
	builder.WriteString("hire_count=")
	builder.WriteString(fmt.Sprintf("%v", e.HireCount))
	builder.WriteString(", ")
	builder.WriteString("service_count=")
	builder.WriteString(fmt.Sprintf("%v", e.ServiceCount))
	builder.WriteString(", ")
	builder.WriteString("achievement_count=")
	builder.WriteString(fmt.Sprintf("%v", e.AchievementCount))
	builder.WriteString(", ")
	builder.WriteString("intro=")
	builder.WriteString(e.Intro)
	builder.WriteString(", ")
	builder.WriteString("estimate=")
	builder.WriteString(e.Estimate)
	builder.WriteString(", ")
	builder.WriteString("skill=")
	builder.WriteString(e.Skill)
	builder.WriteString(", ")
	builder.WriteString("ability_type=")
	builder.WriteString(e.AbilityType)
	builder.WriteString(", ")
	builder.WriteString("scene=")
	builder.WriteString(e.Scene)
	builder.WriteString(", ")
	builder.WriteString("switch_in=")
	builder.WriteString(e.SwitchIn)
	builder.WriteString(", ")
	builder.WriteString("video_url=")
	builder.WriteString(e.VideoURL)
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", e.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("category_id=")
	builder.WriteString(fmt.Sprintf("%v", e.CategoryID))
	builder.WriteString(", ")
	builder.WriteString("api_base=")
	builder.WriteString(e.APIBase)
	builder.WriteString(", ")
	builder.WriteString("api_key=")
	builder.WriteString(e.APIKey)
	builder.WriteString(", ")
	builder.WriteString("ai_info=")
	builder.WriteString(e.AiInfo)
	builder.WriteString(", ")
	builder.WriteString("is_vip=")
	builder.WriteString(fmt.Sprintf("%v", e.IsVip))
	builder.WriteString(", ")
	builder.WriteString("chat_url=")
	builder.WriteString(e.ChatURL)
	builder.WriteByte(')')
	return builder.String()
}

// Employees is a parsable slice of Employee.
type Employees []*Employee
