// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/employee"
	"wechat-api/ent/predicate"
	"wechat-api/ent/tutorial"
	"wechat-api/ent/workexperience"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// EmployeeUpdate is the builder for updating Employee entities.
type EmployeeUpdate struct {
	config
	hooks    []Hook
	mutation *EmployeeMutation
}

// Where appends a list predicates to the EmployeeUpdate builder.
func (eu *EmployeeUpdate) Where(ps ...predicate.Employee) *EmployeeUpdate {
	eu.mutation.Where(ps...)
	return eu
}

// SetUpdatedAt sets the "updated_at" field.
func (eu *EmployeeUpdate) SetUpdatedAt(t time.Time) *EmployeeUpdate {
	eu.mutation.SetUpdatedAt(t)
	return eu
}

// SetDeletedAt sets the "deleted_at" field.
func (eu *EmployeeUpdate) SetDeletedAt(t time.Time) *EmployeeUpdate {
	eu.mutation.SetDeletedAt(t)
	return eu
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableDeletedAt(t *time.Time) *EmployeeUpdate {
	if t != nil {
		eu.SetDeletedAt(*t)
	}
	return eu
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (eu *EmployeeUpdate) ClearDeletedAt() *EmployeeUpdate {
	eu.mutation.ClearDeletedAt()
	return eu
}

// SetTitle sets the "title" field.
func (eu *EmployeeUpdate) SetTitle(s string) *EmployeeUpdate {
	eu.mutation.SetTitle(s)
	return eu
}

// SetNillableTitle sets the "title" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableTitle(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetTitle(*s)
	}
	return eu
}

// SetAvatar sets the "avatar" field.
func (eu *EmployeeUpdate) SetAvatar(s string) *EmployeeUpdate {
	eu.mutation.SetAvatar(s)
	return eu
}

// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableAvatar(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetAvatar(*s)
	}
	return eu
}

// SetTags sets the "tags" field.
func (eu *EmployeeUpdate) SetTags(s string) *EmployeeUpdate {
	eu.mutation.SetTags(s)
	return eu
}

// SetNillableTags sets the "tags" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableTags(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetTags(*s)
	}
	return eu
}

// SetHireCount sets the "hire_count" field.
func (eu *EmployeeUpdate) SetHireCount(i int) *EmployeeUpdate {
	eu.mutation.ResetHireCount()
	eu.mutation.SetHireCount(i)
	return eu
}

// SetNillableHireCount sets the "hire_count" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableHireCount(i *int) *EmployeeUpdate {
	if i != nil {
		eu.SetHireCount(*i)
	}
	return eu
}

// AddHireCount adds i to the "hire_count" field.
func (eu *EmployeeUpdate) AddHireCount(i int) *EmployeeUpdate {
	eu.mutation.AddHireCount(i)
	return eu
}

// SetServiceCount sets the "service_count" field.
func (eu *EmployeeUpdate) SetServiceCount(i int) *EmployeeUpdate {
	eu.mutation.ResetServiceCount()
	eu.mutation.SetServiceCount(i)
	return eu
}

// SetNillableServiceCount sets the "service_count" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableServiceCount(i *int) *EmployeeUpdate {
	if i != nil {
		eu.SetServiceCount(*i)
	}
	return eu
}

// AddServiceCount adds i to the "service_count" field.
func (eu *EmployeeUpdate) AddServiceCount(i int) *EmployeeUpdate {
	eu.mutation.AddServiceCount(i)
	return eu
}

// SetAchievementCount sets the "achievement_count" field.
func (eu *EmployeeUpdate) SetAchievementCount(i int) *EmployeeUpdate {
	eu.mutation.ResetAchievementCount()
	eu.mutation.SetAchievementCount(i)
	return eu
}

// SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableAchievementCount(i *int) *EmployeeUpdate {
	if i != nil {
		eu.SetAchievementCount(*i)
	}
	return eu
}

// AddAchievementCount adds i to the "achievement_count" field.
func (eu *EmployeeUpdate) AddAchievementCount(i int) *EmployeeUpdate {
	eu.mutation.AddAchievementCount(i)
	return eu
}

// SetIntro sets the "intro" field.
func (eu *EmployeeUpdate) SetIntro(s string) *EmployeeUpdate {
	eu.mutation.SetIntro(s)
	return eu
}

// SetNillableIntro sets the "intro" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableIntro(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetIntro(*s)
	}
	return eu
}

// SetEstimate sets the "estimate" field.
func (eu *EmployeeUpdate) SetEstimate(s string) *EmployeeUpdate {
	eu.mutation.SetEstimate(s)
	return eu
}

// SetNillableEstimate sets the "estimate" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableEstimate(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetEstimate(*s)
	}
	return eu
}

// SetSkill sets the "skill" field.
func (eu *EmployeeUpdate) SetSkill(s string) *EmployeeUpdate {
	eu.mutation.SetSkill(s)
	return eu
}

// SetNillableSkill sets the "skill" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableSkill(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetSkill(*s)
	}
	return eu
}

// SetAbilityType sets the "ability_type" field.
func (eu *EmployeeUpdate) SetAbilityType(s string) *EmployeeUpdate {
	eu.mutation.SetAbilityType(s)
	return eu
}

// SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableAbilityType(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetAbilityType(*s)
	}
	return eu
}

// SetScene sets the "scene" field.
func (eu *EmployeeUpdate) SetScene(s string) *EmployeeUpdate {
	eu.mutation.SetScene(s)
	return eu
}

// SetNillableScene sets the "scene" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableScene(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetScene(*s)
	}
	return eu
}

// SetSwitchIn sets the "switch_in" field.
func (eu *EmployeeUpdate) SetSwitchIn(s string) *EmployeeUpdate {
	eu.mutation.SetSwitchIn(s)
	return eu
}

// SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableSwitchIn(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetSwitchIn(*s)
	}
	return eu
}

// SetVideoURL sets the "video_url" field.
func (eu *EmployeeUpdate) SetVideoURL(s string) *EmployeeUpdate {
	eu.mutation.SetVideoURL(s)
	return eu
}

// SetNillableVideoURL sets the "video_url" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableVideoURL(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetVideoURL(*s)
	}
	return eu
}

// SetOrganizationID sets the "organization_id" field.
func (eu *EmployeeUpdate) SetOrganizationID(u uint64) *EmployeeUpdate {
	eu.mutation.ResetOrganizationID()
	eu.mutation.SetOrganizationID(u)
	return eu
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableOrganizationID(u *uint64) *EmployeeUpdate {
	if u != nil {
		eu.SetOrganizationID(*u)
	}
	return eu
}

// AddOrganizationID adds u to the "organization_id" field.
func (eu *EmployeeUpdate) AddOrganizationID(u int64) *EmployeeUpdate {
	eu.mutation.AddOrganizationID(u)
	return eu
}

// SetCategoryID sets the "category_id" field.
func (eu *EmployeeUpdate) SetCategoryID(u uint64) *EmployeeUpdate {
	eu.mutation.ResetCategoryID()
	eu.mutation.SetCategoryID(u)
	return eu
}

// SetNillableCategoryID sets the "category_id" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableCategoryID(u *uint64) *EmployeeUpdate {
	if u != nil {
		eu.SetCategoryID(*u)
	}
	return eu
}

// AddCategoryID adds u to the "category_id" field.
func (eu *EmployeeUpdate) AddCategoryID(u int64) *EmployeeUpdate {
	eu.mutation.AddCategoryID(u)
	return eu
}

// SetAPIBase sets the "api_base" field.
func (eu *EmployeeUpdate) SetAPIBase(s string) *EmployeeUpdate {
	eu.mutation.SetAPIBase(s)
	return eu
}

// SetNillableAPIBase sets the "api_base" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableAPIBase(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetAPIBase(*s)
	}
	return eu
}

// SetAPIKey sets the "api_key" field.
func (eu *EmployeeUpdate) SetAPIKey(s string) *EmployeeUpdate {
	eu.mutation.SetAPIKey(s)
	return eu
}

// SetNillableAPIKey sets the "api_key" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableAPIKey(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetAPIKey(*s)
	}
	return eu
}

// SetAiInfo sets the "ai_info" field.
func (eu *EmployeeUpdate) SetAiInfo(s string) *EmployeeUpdate {
	eu.mutation.SetAiInfo(s)
	return eu
}

// SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableAiInfo(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetAiInfo(*s)
	}
	return eu
}

// ClearAiInfo clears the value of the "ai_info" field.
func (eu *EmployeeUpdate) ClearAiInfo() *EmployeeUpdate {
	eu.mutation.ClearAiInfo()
	return eu
}

// SetIsVip sets the "is_vip" field.
func (eu *EmployeeUpdate) SetIsVip(i int) *EmployeeUpdate {
	eu.mutation.ResetIsVip()
	eu.mutation.SetIsVip(i)
	return eu
}

// SetNillableIsVip sets the "is_vip" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableIsVip(i *int) *EmployeeUpdate {
	if i != nil {
		eu.SetIsVip(*i)
	}
	return eu
}

// AddIsVip adds i to the "is_vip" field.
func (eu *EmployeeUpdate) AddIsVip(i int) *EmployeeUpdate {
	eu.mutation.AddIsVip(i)
	return eu
}

// SetChatURL sets the "chat_url" field.
func (eu *EmployeeUpdate) SetChatURL(s string) *EmployeeUpdate {
	eu.mutation.SetChatURL(s)
	return eu
}

// SetNillableChatURL sets the "chat_url" field if the given value is not nil.
func (eu *EmployeeUpdate) SetNillableChatURL(s *string) *EmployeeUpdate {
	if s != nil {
		eu.SetChatURL(*s)
	}
	return eu
}

// AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
func (eu *EmployeeUpdate) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
	eu.mutation.AddEmWorkExperienceIDs(ids...)
	return eu
}

// AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
func (eu *EmployeeUpdate) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
	ids := make([]uint64, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return eu.AddEmWorkExperienceIDs(ids...)
}

// AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
func (eu *EmployeeUpdate) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
	eu.mutation.AddEmTutorialIDs(ids...)
	return eu
}

// AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
func (eu *EmployeeUpdate) AddEmTutorial(t ...*Tutorial) *EmployeeUpdate {
	ids := make([]uint64, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return eu.AddEmTutorialIDs(ids...)
}

// Mutation returns the EmployeeMutation object of the builder.
func (eu *EmployeeUpdate) Mutation() *EmployeeMutation {
	return eu.mutation
}

// ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
func (eu *EmployeeUpdate) ClearEmWorkExperiences() *EmployeeUpdate {
	eu.mutation.ClearEmWorkExperiences()
	return eu
}

// RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
func (eu *EmployeeUpdate) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
	eu.mutation.RemoveEmWorkExperienceIDs(ids...)
	return eu
}

// RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
func (eu *EmployeeUpdate) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
	ids := make([]uint64, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return eu.RemoveEmWorkExperienceIDs(ids...)
}

// ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
func (eu *EmployeeUpdate) ClearEmTutorial() *EmployeeUpdate {
	eu.mutation.ClearEmTutorial()
	return eu
}

// RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
func (eu *EmployeeUpdate) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
	eu.mutation.RemoveEmTutorialIDs(ids...)
	return eu
}

// RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
func (eu *EmployeeUpdate) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdate {
	ids := make([]uint64, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return eu.RemoveEmTutorialIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (eu *EmployeeUpdate) Save(ctx context.Context) (int, error) {
	if err := eu.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (eu *EmployeeUpdate) SaveX(ctx context.Context) int {
	affected, err := eu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (eu *EmployeeUpdate) Exec(ctx context.Context) error {
	_, err := eu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (eu *EmployeeUpdate) ExecX(ctx context.Context) {
	if err := eu.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (eu *EmployeeUpdate) defaults() error {
	if _, ok := eu.mutation.UpdatedAt(); !ok {
		if employee.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := employee.UpdateDefaultUpdatedAt()
		eu.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (eu *EmployeeUpdate) check() error {
	if v, ok := eu.mutation.Title(); ok {
		if err := employee.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
		}
	}
	if v, ok := eu.mutation.HireCount(); ok {
		if err := employee.HireCountValidator(v); err != nil {
			return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
		}
	}
	if v, ok := eu.mutation.ServiceCount(); ok {
		if err := employee.ServiceCountValidator(v); err != nil {
			return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
		}
	}
	if v, ok := eu.mutation.AchievementCount(); ok {
		if err := employee.AchievementCountValidator(v); err != nil {
			return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
		}
	}
	if v, ok := eu.mutation.OrganizationID(); ok {
		if err := employee.OrganizationIDValidator(v); err != nil {
			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
		}
	}
	if v, ok := eu.mutation.CategoryID(); ok {
		if err := employee.CategoryIDValidator(v); err != nil {
			return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
		}
	}
	return nil
}

func (eu *EmployeeUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := eu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
	if ps := eu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := eu.mutation.UpdatedAt(); ok {
		_spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := eu.mutation.DeletedAt(); ok {
		_spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
	}
	if eu.mutation.DeletedAtCleared() {
		_spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := eu.mutation.Title(); ok {
		_spec.SetField(employee.FieldTitle, field.TypeString, value)
	}
	if value, ok := eu.mutation.Avatar(); ok {
		_spec.SetField(employee.FieldAvatar, field.TypeString, value)
	}
	if value, ok := eu.mutation.Tags(); ok {
		_spec.SetField(employee.FieldTags, field.TypeString, value)
	}
	if value, ok := eu.mutation.HireCount(); ok {
		_spec.SetField(employee.FieldHireCount, field.TypeInt, value)
	}
	if value, ok := eu.mutation.AddedHireCount(); ok {
		_spec.AddField(employee.FieldHireCount, field.TypeInt, value)
	}
	if value, ok := eu.mutation.ServiceCount(); ok {
		_spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
	}
	if value, ok := eu.mutation.AddedServiceCount(); ok {
		_spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
	}
	if value, ok := eu.mutation.AchievementCount(); ok {
		_spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
	}
	if value, ok := eu.mutation.AddedAchievementCount(); ok {
		_spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
	}
	if value, ok := eu.mutation.Intro(); ok {
		_spec.SetField(employee.FieldIntro, field.TypeString, value)
	}
	if value, ok := eu.mutation.Estimate(); ok {
		_spec.SetField(employee.FieldEstimate, field.TypeString, value)
	}
	if value, ok := eu.mutation.Skill(); ok {
		_spec.SetField(employee.FieldSkill, field.TypeString, value)
	}
	if value, ok := eu.mutation.AbilityType(); ok {
		_spec.SetField(employee.FieldAbilityType, field.TypeString, value)
	}
	if value, ok := eu.mutation.Scene(); ok {
		_spec.SetField(employee.FieldScene, field.TypeString, value)
	}
	if value, ok := eu.mutation.SwitchIn(); ok {
		_spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
	}
	if value, ok := eu.mutation.VideoURL(); ok {
		_spec.SetField(employee.FieldVideoURL, field.TypeString, value)
	}
	if value, ok := eu.mutation.OrganizationID(); ok {
		_spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := eu.mutation.AddedOrganizationID(); ok {
		_spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := eu.mutation.CategoryID(); ok {
		_spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
	}
	if value, ok := eu.mutation.AddedCategoryID(); ok {
		_spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
	}
	if value, ok := eu.mutation.APIBase(); ok {
		_spec.SetField(employee.FieldAPIBase, field.TypeString, value)
	}
	if value, ok := eu.mutation.APIKey(); ok {
		_spec.SetField(employee.FieldAPIKey, field.TypeString, value)
	}
	if value, ok := eu.mutation.AiInfo(); ok {
		_spec.SetField(employee.FieldAiInfo, field.TypeString, value)
	}
	if eu.mutation.AiInfoCleared() {
		_spec.ClearField(employee.FieldAiInfo, field.TypeString)
	}
	if value, ok := eu.mutation.IsVip(); ok {
		_spec.SetField(employee.FieldIsVip, field.TypeInt, value)
	}
	if value, ok := eu.mutation.AddedIsVip(); ok {
		_spec.AddField(employee.FieldIsVip, field.TypeInt, value)
	}
	if value, ok := eu.mutation.ChatURL(); ok {
		_spec.SetField(employee.FieldChatURL, field.TypeString, value)
	}
	if eu.mutation.EmWorkExperiencesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmWorkExperiencesTable,
			Columns: []string{employee.EmWorkExperiencesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := eu.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !eu.mutation.EmWorkExperiencesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmWorkExperiencesTable,
			Columns: []string{employee.EmWorkExperiencesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := eu.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmWorkExperiencesTable,
			Columns: []string{employee.EmWorkExperiencesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if eu.mutation.EmTutorialCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmTutorialTable,
			Columns: []string{employee.EmTutorialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := eu.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !eu.mutation.EmTutorialCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmTutorialTable,
			Columns: []string{employee.EmTutorialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := eu.mutation.EmTutorialIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmTutorialTable,
			Columns: []string{employee.EmTutorialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{employee.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	eu.mutation.done = true
	return n, nil
}

// EmployeeUpdateOne is the builder for updating a single Employee entity.
type EmployeeUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *EmployeeMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (euo *EmployeeUpdateOne) SetUpdatedAt(t time.Time) *EmployeeUpdateOne {
	euo.mutation.SetUpdatedAt(t)
	return euo
}

// SetDeletedAt sets the "deleted_at" field.
func (euo *EmployeeUpdateOne) SetDeletedAt(t time.Time) *EmployeeUpdateOne {
	euo.mutation.SetDeletedAt(t)
	return euo
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableDeletedAt(t *time.Time) *EmployeeUpdateOne {
	if t != nil {
		euo.SetDeletedAt(*t)
	}
	return euo
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (euo *EmployeeUpdateOne) ClearDeletedAt() *EmployeeUpdateOne {
	euo.mutation.ClearDeletedAt()
	return euo
}

// SetTitle sets the "title" field.
func (euo *EmployeeUpdateOne) SetTitle(s string) *EmployeeUpdateOne {
	euo.mutation.SetTitle(s)
	return euo
}

// SetNillableTitle sets the "title" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableTitle(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetTitle(*s)
	}
	return euo
}

// SetAvatar sets the "avatar" field.
func (euo *EmployeeUpdateOne) SetAvatar(s string) *EmployeeUpdateOne {
	euo.mutation.SetAvatar(s)
	return euo
}

// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableAvatar(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetAvatar(*s)
	}
	return euo
}

// SetTags sets the "tags" field.
func (euo *EmployeeUpdateOne) SetTags(s string) *EmployeeUpdateOne {
	euo.mutation.SetTags(s)
	return euo
}

// SetNillableTags sets the "tags" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableTags(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetTags(*s)
	}
	return euo
}

// SetHireCount sets the "hire_count" field.
func (euo *EmployeeUpdateOne) SetHireCount(i int) *EmployeeUpdateOne {
	euo.mutation.ResetHireCount()
	euo.mutation.SetHireCount(i)
	return euo
}

// SetNillableHireCount sets the "hire_count" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableHireCount(i *int) *EmployeeUpdateOne {
	if i != nil {
		euo.SetHireCount(*i)
	}
	return euo
}

// AddHireCount adds i to the "hire_count" field.
func (euo *EmployeeUpdateOne) AddHireCount(i int) *EmployeeUpdateOne {
	euo.mutation.AddHireCount(i)
	return euo
}

// SetServiceCount sets the "service_count" field.
func (euo *EmployeeUpdateOne) SetServiceCount(i int) *EmployeeUpdateOne {
	euo.mutation.ResetServiceCount()
	euo.mutation.SetServiceCount(i)
	return euo
}

// SetNillableServiceCount sets the "service_count" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableServiceCount(i *int) *EmployeeUpdateOne {
	if i != nil {
		euo.SetServiceCount(*i)
	}
	return euo
}

// AddServiceCount adds i to the "service_count" field.
func (euo *EmployeeUpdateOne) AddServiceCount(i int) *EmployeeUpdateOne {
	euo.mutation.AddServiceCount(i)
	return euo
}

// SetAchievementCount sets the "achievement_count" field.
func (euo *EmployeeUpdateOne) SetAchievementCount(i int) *EmployeeUpdateOne {
	euo.mutation.ResetAchievementCount()
	euo.mutation.SetAchievementCount(i)
	return euo
}

// SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableAchievementCount(i *int) *EmployeeUpdateOne {
	if i != nil {
		euo.SetAchievementCount(*i)
	}
	return euo
}

// AddAchievementCount adds i to the "achievement_count" field.
func (euo *EmployeeUpdateOne) AddAchievementCount(i int) *EmployeeUpdateOne {
	euo.mutation.AddAchievementCount(i)
	return euo
}

// SetIntro sets the "intro" field.
func (euo *EmployeeUpdateOne) SetIntro(s string) *EmployeeUpdateOne {
	euo.mutation.SetIntro(s)
	return euo
}

// SetNillableIntro sets the "intro" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableIntro(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetIntro(*s)
	}
	return euo
}

// SetEstimate sets the "estimate" field.
func (euo *EmployeeUpdateOne) SetEstimate(s string) *EmployeeUpdateOne {
	euo.mutation.SetEstimate(s)
	return euo
}

// SetNillableEstimate sets the "estimate" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableEstimate(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetEstimate(*s)
	}
	return euo
}

// SetSkill sets the "skill" field.
func (euo *EmployeeUpdateOne) SetSkill(s string) *EmployeeUpdateOne {
	euo.mutation.SetSkill(s)
	return euo
}

// SetNillableSkill sets the "skill" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableSkill(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetSkill(*s)
	}
	return euo
}

// SetAbilityType sets the "ability_type" field.
func (euo *EmployeeUpdateOne) SetAbilityType(s string) *EmployeeUpdateOne {
	euo.mutation.SetAbilityType(s)
	return euo
}

// SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableAbilityType(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetAbilityType(*s)
	}
	return euo
}

// SetScene sets the "scene" field.
func (euo *EmployeeUpdateOne) SetScene(s string) *EmployeeUpdateOne {
	euo.mutation.SetScene(s)
	return euo
}

// SetNillableScene sets the "scene" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableScene(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetScene(*s)
	}
	return euo
}

// SetSwitchIn sets the "switch_in" field.
func (euo *EmployeeUpdateOne) SetSwitchIn(s string) *EmployeeUpdateOne {
	euo.mutation.SetSwitchIn(s)
	return euo
}

// SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableSwitchIn(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetSwitchIn(*s)
	}
	return euo
}

// SetVideoURL sets the "video_url" field.
func (euo *EmployeeUpdateOne) SetVideoURL(s string) *EmployeeUpdateOne {
	euo.mutation.SetVideoURL(s)
	return euo
}

// SetNillableVideoURL sets the "video_url" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableVideoURL(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetVideoURL(*s)
	}
	return euo
}

// SetOrganizationID sets the "organization_id" field.
func (euo *EmployeeUpdateOne) SetOrganizationID(u uint64) *EmployeeUpdateOne {
	euo.mutation.ResetOrganizationID()
	euo.mutation.SetOrganizationID(u)
	return euo
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableOrganizationID(u *uint64) *EmployeeUpdateOne {
	if u != nil {
		euo.SetOrganizationID(*u)
	}
	return euo
}

// AddOrganizationID adds u to the "organization_id" field.
func (euo *EmployeeUpdateOne) AddOrganizationID(u int64) *EmployeeUpdateOne {
	euo.mutation.AddOrganizationID(u)
	return euo
}

// SetCategoryID sets the "category_id" field.
func (euo *EmployeeUpdateOne) SetCategoryID(u uint64) *EmployeeUpdateOne {
	euo.mutation.ResetCategoryID()
	euo.mutation.SetCategoryID(u)
	return euo
}

// SetNillableCategoryID sets the "category_id" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableCategoryID(u *uint64) *EmployeeUpdateOne {
	if u != nil {
		euo.SetCategoryID(*u)
	}
	return euo
}

// AddCategoryID adds u to the "category_id" field.
func (euo *EmployeeUpdateOne) AddCategoryID(u int64) *EmployeeUpdateOne {
	euo.mutation.AddCategoryID(u)
	return euo
}

// SetAPIBase sets the "api_base" field.
func (euo *EmployeeUpdateOne) SetAPIBase(s string) *EmployeeUpdateOne {
	euo.mutation.SetAPIBase(s)
	return euo
}

// SetNillableAPIBase sets the "api_base" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableAPIBase(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetAPIBase(*s)
	}
	return euo
}

// SetAPIKey sets the "api_key" field.
func (euo *EmployeeUpdateOne) SetAPIKey(s string) *EmployeeUpdateOne {
	euo.mutation.SetAPIKey(s)
	return euo
}

// SetNillableAPIKey sets the "api_key" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableAPIKey(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetAPIKey(*s)
	}
	return euo
}

// SetAiInfo sets the "ai_info" field.
func (euo *EmployeeUpdateOne) SetAiInfo(s string) *EmployeeUpdateOne {
	euo.mutation.SetAiInfo(s)
	return euo
}

// SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableAiInfo(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetAiInfo(*s)
	}
	return euo
}

// ClearAiInfo clears the value of the "ai_info" field.
func (euo *EmployeeUpdateOne) ClearAiInfo() *EmployeeUpdateOne {
	euo.mutation.ClearAiInfo()
	return euo
}

// SetIsVip sets the "is_vip" field.
func (euo *EmployeeUpdateOne) SetIsVip(i int) *EmployeeUpdateOne {
	euo.mutation.ResetIsVip()
	euo.mutation.SetIsVip(i)
	return euo
}

// SetNillableIsVip sets the "is_vip" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableIsVip(i *int) *EmployeeUpdateOne {
	if i != nil {
		euo.SetIsVip(*i)
	}
	return euo
}

// AddIsVip adds i to the "is_vip" field.
func (euo *EmployeeUpdateOne) AddIsVip(i int) *EmployeeUpdateOne {
	euo.mutation.AddIsVip(i)
	return euo
}

// SetChatURL sets the "chat_url" field.
func (euo *EmployeeUpdateOne) SetChatURL(s string) *EmployeeUpdateOne {
	euo.mutation.SetChatURL(s)
	return euo
}

// SetNillableChatURL sets the "chat_url" field if the given value is not nil.
func (euo *EmployeeUpdateOne) SetNillableChatURL(s *string) *EmployeeUpdateOne {
	if s != nil {
		euo.SetChatURL(*s)
	}
	return euo
}

// AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
func (euo *EmployeeUpdateOne) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
	euo.mutation.AddEmWorkExperienceIDs(ids...)
	return euo
}

// AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
func (euo *EmployeeUpdateOne) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
	ids := make([]uint64, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return euo.AddEmWorkExperienceIDs(ids...)
}

// AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
func (euo *EmployeeUpdateOne) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
	euo.mutation.AddEmTutorialIDs(ids...)
	return euo
}

// AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
func (euo *EmployeeUpdateOne) AddEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
	ids := make([]uint64, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return euo.AddEmTutorialIDs(ids...)
}

// Mutation returns the EmployeeMutation object of the builder.
func (euo *EmployeeUpdateOne) Mutation() *EmployeeMutation {
	return euo.mutation
}

// ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
func (euo *EmployeeUpdateOne) ClearEmWorkExperiences() *EmployeeUpdateOne {
	euo.mutation.ClearEmWorkExperiences()
	return euo
}

// RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
func (euo *EmployeeUpdateOne) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
	euo.mutation.RemoveEmWorkExperienceIDs(ids...)
	return euo
}

// RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
func (euo *EmployeeUpdateOne) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
	ids := make([]uint64, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return euo.RemoveEmWorkExperienceIDs(ids...)
}

// ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
func (euo *EmployeeUpdateOne) ClearEmTutorial() *EmployeeUpdateOne {
	euo.mutation.ClearEmTutorial()
	return euo
}

// RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
func (euo *EmployeeUpdateOne) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
	euo.mutation.RemoveEmTutorialIDs(ids...)
	return euo
}

// RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
func (euo *EmployeeUpdateOne) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
	ids := make([]uint64, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return euo.RemoveEmTutorialIDs(ids...)
}

// Where appends a list predicates to the EmployeeUpdate builder.
func (euo *EmployeeUpdateOne) Where(ps ...predicate.Employee) *EmployeeUpdateOne {
	euo.mutation.Where(ps...)
	return euo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (euo *EmployeeUpdateOne) Select(field string, fields ...string) *EmployeeUpdateOne {
	euo.fields = append([]string{field}, fields...)
	return euo
}

// Save executes the query and returns the updated Employee entity.
func (euo *EmployeeUpdateOne) Save(ctx context.Context) (*Employee, error) {
	if err := euo.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (euo *EmployeeUpdateOne) SaveX(ctx context.Context) *Employee {
	node, err := euo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (euo *EmployeeUpdateOne) Exec(ctx context.Context) error {
	_, err := euo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (euo *EmployeeUpdateOne) ExecX(ctx context.Context) {
	if err := euo.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (euo *EmployeeUpdateOne) defaults() error {
	if _, ok := euo.mutation.UpdatedAt(); !ok {
		if employee.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := employee.UpdateDefaultUpdatedAt()
		euo.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (euo *EmployeeUpdateOne) check() error {
	if v, ok := euo.mutation.Title(); ok {
		if err := employee.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
		}
	}
	if v, ok := euo.mutation.HireCount(); ok {
		if err := employee.HireCountValidator(v); err != nil {
			return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
		}
	}
	if v, ok := euo.mutation.ServiceCount(); ok {
		if err := employee.ServiceCountValidator(v); err != nil {
			return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
		}
	}
	if v, ok := euo.mutation.AchievementCount(); ok {
		if err := employee.AchievementCountValidator(v); err != nil {
			return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
		}
	}
	if v, ok := euo.mutation.OrganizationID(); ok {
		if err := employee.OrganizationIDValidator(v); err != nil {
			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
		}
	}
	if v, ok := euo.mutation.CategoryID(); ok {
		if err := employee.CategoryIDValidator(v); err != nil {
			return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
		}
	}
	return nil
}

func (euo *EmployeeUpdateOne) sqlSave(ctx context.Context) (_node *Employee, err error) {
	if err := euo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
	id, ok := euo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Employee.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := euo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, employee.FieldID)
		for _, f := range fields {
			if !employee.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != employee.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := euo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := euo.mutation.UpdatedAt(); ok {
		_spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := euo.mutation.DeletedAt(); ok {
		_spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
	}
	if euo.mutation.DeletedAtCleared() {
		_spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := euo.mutation.Title(); ok {
		_spec.SetField(employee.FieldTitle, field.TypeString, value)
	}
	if value, ok := euo.mutation.Avatar(); ok {
		_spec.SetField(employee.FieldAvatar, field.TypeString, value)
	}
	if value, ok := euo.mutation.Tags(); ok {
		_spec.SetField(employee.FieldTags, field.TypeString, value)
	}
	if value, ok := euo.mutation.HireCount(); ok {
		_spec.SetField(employee.FieldHireCount, field.TypeInt, value)
	}
	if value, ok := euo.mutation.AddedHireCount(); ok {
		_spec.AddField(employee.FieldHireCount, field.TypeInt, value)
	}
	if value, ok := euo.mutation.ServiceCount(); ok {
		_spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
	}
	if value, ok := euo.mutation.AddedServiceCount(); ok {
		_spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
	}
	if value, ok := euo.mutation.AchievementCount(); ok {
		_spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
	}
	if value, ok := euo.mutation.AddedAchievementCount(); ok {
		_spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
	}
	if value, ok := euo.mutation.Intro(); ok {
		_spec.SetField(employee.FieldIntro, field.TypeString, value)
	}
	if value, ok := euo.mutation.Estimate(); ok {
		_spec.SetField(employee.FieldEstimate, field.TypeString, value)
	}
	if value, ok := euo.mutation.Skill(); ok {
		_spec.SetField(employee.FieldSkill, field.TypeString, value)
	}
	if value, ok := euo.mutation.AbilityType(); ok {
		_spec.SetField(employee.FieldAbilityType, field.TypeString, value)
	}
	if value, ok := euo.mutation.Scene(); ok {
		_spec.SetField(employee.FieldScene, field.TypeString, value)
	}
	if value, ok := euo.mutation.SwitchIn(); ok {
		_spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
	}
	if value, ok := euo.mutation.VideoURL(); ok {
		_spec.SetField(employee.FieldVideoURL, field.TypeString, value)
	}
	if value, ok := euo.mutation.OrganizationID(); ok {
		_spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := euo.mutation.AddedOrganizationID(); ok {
		_spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := euo.mutation.CategoryID(); ok {
		_spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
	}
	if value, ok := euo.mutation.AddedCategoryID(); ok {
		_spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
	}
	if value, ok := euo.mutation.APIBase(); ok {
		_spec.SetField(employee.FieldAPIBase, field.TypeString, value)
	}
	if value, ok := euo.mutation.APIKey(); ok {
		_spec.SetField(employee.FieldAPIKey, field.TypeString, value)
	}
	if value, ok := euo.mutation.AiInfo(); ok {
		_spec.SetField(employee.FieldAiInfo, field.TypeString, value)
	}
	if euo.mutation.AiInfoCleared() {
		_spec.ClearField(employee.FieldAiInfo, field.TypeString)
	}
	if value, ok := euo.mutation.IsVip(); ok {
		_spec.SetField(employee.FieldIsVip, field.TypeInt, value)
	}
	if value, ok := euo.mutation.AddedIsVip(); ok {
		_spec.AddField(employee.FieldIsVip, field.TypeInt, value)
	}
	if value, ok := euo.mutation.ChatURL(); ok {
		_spec.SetField(employee.FieldChatURL, field.TypeString, value)
	}
	if euo.mutation.EmWorkExperiencesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmWorkExperiencesTable,
			Columns: []string{employee.EmWorkExperiencesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := euo.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !euo.mutation.EmWorkExperiencesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmWorkExperiencesTable,
			Columns: []string{employee.EmWorkExperiencesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := euo.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmWorkExperiencesTable,
			Columns: []string{employee.EmWorkExperiencesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if euo.mutation.EmTutorialCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmTutorialTable,
			Columns: []string{employee.EmTutorialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := euo.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !euo.mutation.EmTutorialCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmTutorialTable,
			Columns: []string{employee.EmTutorialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := euo.mutation.EmTutorialIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   employee.EmTutorialTable,
			Columns: []string{employee.EmTutorialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Employee{config: euo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{employee.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	euo.mutation.done = true
	return _node, nil
}