// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/aliyunavatar"

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

// AliyunAvatarCreate is the builder for creating a AliyunAvatar entity.
type AliyunAvatarCreate struct {
	config
	mutation *AliyunAvatarMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (aac *AliyunAvatarCreate) SetCreatedAt(t time.Time) *AliyunAvatarCreate {
	aac.mutation.SetCreatedAt(t)
	return aac
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (aac *AliyunAvatarCreate) SetNillableCreatedAt(t *time.Time) *AliyunAvatarCreate {
	if t != nil {
		aac.SetCreatedAt(*t)
	}
	return aac
}

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

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (aac *AliyunAvatarCreate) SetNillableUpdatedAt(t *time.Time) *AliyunAvatarCreate {
	if t != nil {
		aac.SetUpdatedAt(*t)
	}
	return aac
}

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

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

// SetUserID sets the "user_id" field.
func (aac *AliyunAvatarCreate) SetUserID(u uint64) *AliyunAvatarCreate {
	aac.mutation.SetUserID(u)
	return aac
}

// SetBizID sets the "biz_id" field.
func (aac *AliyunAvatarCreate) SetBizID(s string) *AliyunAvatarCreate {
	aac.mutation.SetBizID(s)
	return aac
}

// SetAccessKeyID sets the "access_key_id" field.
func (aac *AliyunAvatarCreate) SetAccessKeyID(s string) *AliyunAvatarCreate {
	aac.mutation.SetAccessKeyID(s)
	return aac
}

// SetAccessKeySecret sets the "access_key_secret" field.
func (aac *AliyunAvatarCreate) SetAccessKeySecret(s string) *AliyunAvatarCreate {
	aac.mutation.SetAccessKeySecret(s)
	return aac
}

// SetAppID sets the "app_id" field.
func (aac *AliyunAvatarCreate) SetAppID(s string) *AliyunAvatarCreate {
	aac.mutation.SetAppID(s)
	return aac
}

// SetNillableAppID sets the "app_id" field if the given value is not nil.
func (aac *AliyunAvatarCreate) SetNillableAppID(s *string) *AliyunAvatarCreate {
	if s != nil {
		aac.SetAppID(*s)
	}
	return aac
}

// SetTenantID sets the "tenant_id" field.
func (aac *AliyunAvatarCreate) SetTenantID(u uint64) *AliyunAvatarCreate {
	aac.mutation.SetTenantID(u)
	return aac
}

// SetResponse sets the "response" field.
func (aac *AliyunAvatarCreate) SetResponse(s string) *AliyunAvatarCreate {
	aac.mutation.SetResponse(s)
	return aac
}

// SetToken sets the "token" field.
func (aac *AliyunAvatarCreate) SetToken(s string) *AliyunAvatarCreate {
	aac.mutation.SetToken(s)
	return aac
}

// SetNillableToken sets the "token" field if the given value is not nil.
func (aac *AliyunAvatarCreate) SetNillableToken(s *string) *AliyunAvatarCreate {
	if s != nil {
		aac.SetToken(*s)
	}
	return aac
}

// SetSessionID sets the "session_id" field.
func (aac *AliyunAvatarCreate) SetSessionID(s string) *AliyunAvatarCreate {
	aac.mutation.SetSessionID(s)
	return aac
}

// SetNillableSessionID sets the "session_id" field if the given value is not nil.
func (aac *AliyunAvatarCreate) SetNillableSessionID(s *string) *AliyunAvatarCreate {
	if s != nil {
		aac.SetSessionID(*s)
	}
	return aac
}

// SetID sets the "id" field.
func (aac *AliyunAvatarCreate) SetID(u uint64) *AliyunAvatarCreate {
	aac.mutation.SetID(u)
	return aac
}

// Mutation returns the AliyunAvatarMutation object of the builder.
func (aac *AliyunAvatarCreate) Mutation() *AliyunAvatarMutation {
	return aac.mutation
}

// Save creates the AliyunAvatar in the database.
func (aac *AliyunAvatarCreate) Save(ctx context.Context) (*AliyunAvatar, error) {
	if err := aac.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, aac.sqlSave, aac.mutation, aac.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (aac *AliyunAvatarCreate) SaveX(ctx context.Context) *AliyunAvatar {
	v, err := aac.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// defaults sets the default values of the builder before save.
func (aac *AliyunAvatarCreate) defaults() error {
	if _, ok := aac.mutation.CreatedAt(); !ok {
		if aliyunavatar.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized aliyunavatar.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := aliyunavatar.DefaultCreatedAt()
		aac.mutation.SetCreatedAt(v)
	}
	if _, ok := aac.mutation.UpdatedAt(); !ok {
		if aliyunavatar.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized aliyunavatar.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := aliyunavatar.DefaultUpdatedAt()
		aac.mutation.SetUpdatedAt(v)
	}
	if _, ok := aac.mutation.Token(); !ok {
		v := aliyunavatar.DefaultToken
		aac.mutation.SetToken(v)
	}
	if _, ok := aac.mutation.SessionID(); !ok {
		v := aliyunavatar.DefaultSessionID
		aac.mutation.SetSessionID(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (aac *AliyunAvatarCreate) check() error {
	if _, ok := aac.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AliyunAvatar.created_at"`)}
	}
	if _, ok := aac.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AliyunAvatar.updated_at"`)}
	}
	if _, ok := aac.mutation.UserID(); !ok {
		return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "AliyunAvatar.user_id"`)}
	}
	if _, ok := aac.mutation.BizID(); !ok {
		return &ValidationError{Name: "biz_id", err: errors.New(`ent: missing required field "AliyunAvatar.biz_id"`)}
	}
	if _, ok := aac.mutation.AccessKeyID(); !ok {
		return &ValidationError{Name: "access_key_id", err: errors.New(`ent: missing required field "AliyunAvatar.access_key_id"`)}
	}
	if _, ok := aac.mutation.AccessKeySecret(); !ok {
		return &ValidationError{Name: "access_key_secret", err: errors.New(`ent: missing required field "AliyunAvatar.access_key_secret"`)}
	}
	if _, ok := aac.mutation.TenantID(); !ok {
		return &ValidationError{Name: "tenant_id", err: errors.New(`ent: missing required field "AliyunAvatar.tenant_id"`)}
	}
	if _, ok := aac.mutation.Response(); !ok {
		return &ValidationError{Name: "response", err: errors.New(`ent: missing required field "AliyunAvatar.response"`)}
	}
	if _, ok := aac.mutation.Token(); !ok {
		return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "AliyunAvatar.token"`)}
	}
	if _, ok := aac.mutation.SessionID(); !ok {
		return &ValidationError{Name: "session_id", err: errors.New(`ent: missing required field "AliyunAvatar.session_id"`)}
	}
	return nil
}

func (aac *AliyunAvatarCreate) sqlSave(ctx context.Context) (*AliyunAvatar, error) {
	if err := aac.check(); err != nil {
		return nil, err
	}
	_node, _spec := aac.createSpec()
	if err := sqlgraph.CreateNode(ctx, aac.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = uint64(id)
	}
	aac.mutation.id = &_node.ID
	aac.mutation.done = true
	return _node, nil
}

func (aac *AliyunAvatarCreate) createSpec() (*AliyunAvatar, *sqlgraph.CreateSpec) {
	var (
		_node = &AliyunAvatar{config: aac.config}
		_spec = sqlgraph.NewCreateSpec(aliyunavatar.Table, sqlgraph.NewFieldSpec(aliyunavatar.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = aac.conflict
	if id, ok := aac.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := aac.mutation.CreatedAt(); ok {
		_spec.SetField(aliyunavatar.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := aac.mutation.UpdatedAt(); ok {
		_spec.SetField(aliyunavatar.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := aac.mutation.DeletedAt(); ok {
		_spec.SetField(aliyunavatar.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := aac.mutation.UserID(); ok {
		_spec.SetField(aliyunavatar.FieldUserID, field.TypeUint64, value)
		_node.UserID = value
	}
	if value, ok := aac.mutation.BizID(); ok {
		_spec.SetField(aliyunavatar.FieldBizID, field.TypeString, value)
		_node.BizID = value
	}
	if value, ok := aac.mutation.AccessKeyID(); ok {
		_spec.SetField(aliyunavatar.FieldAccessKeyID, field.TypeString, value)
		_node.AccessKeyID = value
	}
	if value, ok := aac.mutation.AccessKeySecret(); ok {
		_spec.SetField(aliyunavatar.FieldAccessKeySecret, field.TypeString, value)
		_node.AccessKeySecret = value
	}
	if value, ok := aac.mutation.AppID(); ok {
		_spec.SetField(aliyunavatar.FieldAppID, field.TypeString, value)
		_node.AppID = value
	}
	if value, ok := aac.mutation.TenantID(); ok {
		_spec.SetField(aliyunavatar.FieldTenantID, field.TypeUint64, value)
		_node.TenantID = value
	}
	if value, ok := aac.mutation.Response(); ok {
		_spec.SetField(aliyunavatar.FieldResponse, field.TypeString, value)
		_node.Response = value
	}
	if value, ok := aac.mutation.Token(); ok {
		_spec.SetField(aliyunavatar.FieldToken, field.TypeString, value)
		_node.Token = value
	}
	if value, ok := aac.mutation.SessionID(); ok {
		_spec.SetField(aliyunavatar.FieldSessionID, field.TypeString, value)
		_node.SessionID = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.AliyunAvatar.Create().
//		SetCreatedAt(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.AliyunAvatarUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (aac *AliyunAvatarCreate) OnConflict(opts ...sql.ConflictOption) *AliyunAvatarUpsertOne {
	aac.conflict = opts
	return &AliyunAvatarUpsertOne{
		create: aac,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.AliyunAvatar.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (aac *AliyunAvatarCreate) OnConflictColumns(columns ...string) *AliyunAvatarUpsertOne {
	aac.conflict = append(aac.conflict, sql.ConflictColumns(columns...))
	return &AliyunAvatarUpsertOne{
		create: aac,
	}
}

type (
	// AliyunAvatarUpsertOne is the builder for "upsert"-ing
	//  one AliyunAvatar node.
	AliyunAvatarUpsertOne struct {
		create *AliyunAvatarCreate
	}

	// AliyunAvatarUpsert is the "OnConflict" setter.
	AliyunAvatarUpsert struct {
		*sql.UpdateSet
	}
)

// SetUpdatedAt sets the "updated_at" field.
func (u *AliyunAvatarUpsert) SetUpdatedAt(v time.Time) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldUpdatedAt, v)
	return u
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateUpdatedAt() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldUpdatedAt)
	return u
}

// SetDeletedAt sets the "deleted_at" field.
func (u *AliyunAvatarUpsert) SetDeletedAt(v time.Time) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldDeletedAt, v)
	return u
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateDeletedAt() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldDeletedAt)
	return u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *AliyunAvatarUpsert) ClearDeletedAt() *AliyunAvatarUpsert {
	u.SetNull(aliyunavatar.FieldDeletedAt)
	return u
}

// SetUserID sets the "user_id" field.
func (u *AliyunAvatarUpsert) SetUserID(v uint64) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldUserID, v)
	return u
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateUserID() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldUserID)
	return u
}

// AddUserID adds v to the "user_id" field.
func (u *AliyunAvatarUpsert) AddUserID(v uint64) *AliyunAvatarUpsert {
	u.Add(aliyunavatar.FieldUserID, v)
	return u
}

// SetBizID sets the "biz_id" field.
func (u *AliyunAvatarUpsert) SetBizID(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldBizID, v)
	return u
}

// UpdateBizID sets the "biz_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateBizID() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldBizID)
	return u
}

// SetAccessKeyID sets the "access_key_id" field.
func (u *AliyunAvatarUpsert) SetAccessKeyID(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldAccessKeyID, v)
	return u
}

// UpdateAccessKeyID sets the "access_key_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateAccessKeyID() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldAccessKeyID)
	return u
}

// SetAccessKeySecret sets the "access_key_secret" field.
func (u *AliyunAvatarUpsert) SetAccessKeySecret(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldAccessKeySecret, v)
	return u
}

// UpdateAccessKeySecret sets the "access_key_secret" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateAccessKeySecret() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldAccessKeySecret)
	return u
}

// SetAppID sets the "app_id" field.
func (u *AliyunAvatarUpsert) SetAppID(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldAppID, v)
	return u
}

// UpdateAppID sets the "app_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateAppID() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldAppID)
	return u
}

// ClearAppID clears the value of the "app_id" field.
func (u *AliyunAvatarUpsert) ClearAppID() *AliyunAvatarUpsert {
	u.SetNull(aliyunavatar.FieldAppID)
	return u
}

// SetTenantID sets the "tenant_id" field.
func (u *AliyunAvatarUpsert) SetTenantID(v uint64) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldTenantID, v)
	return u
}

// UpdateTenantID sets the "tenant_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateTenantID() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldTenantID)
	return u
}

// AddTenantID adds v to the "tenant_id" field.
func (u *AliyunAvatarUpsert) AddTenantID(v uint64) *AliyunAvatarUpsert {
	u.Add(aliyunavatar.FieldTenantID, v)
	return u
}

// SetResponse sets the "response" field.
func (u *AliyunAvatarUpsert) SetResponse(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldResponse, v)
	return u
}

// UpdateResponse sets the "response" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateResponse() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldResponse)
	return u
}

// SetToken sets the "token" field.
func (u *AliyunAvatarUpsert) SetToken(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldToken, v)
	return u
}

// UpdateToken sets the "token" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateToken() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldToken)
	return u
}

// SetSessionID sets the "session_id" field.
func (u *AliyunAvatarUpsert) SetSessionID(v string) *AliyunAvatarUpsert {
	u.Set(aliyunavatar.FieldSessionID, v)
	return u
}

// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsert) UpdateSessionID() *AliyunAvatarUpsert {
	u.SetExcluded(aliyunavatar.FieldSessionID)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.AliyunAvatar.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(aliyunavatar.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *AliyunAvatarUpsertOne) UpdateNewValues() *AliyunAvatarUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(aliyunavatar.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(aliyunavatar.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.AliyunAvatar.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *AliyunAvatarUpsertOne) Ignore() *AliyunAvatarUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *AliyunAvatarUpsertOne) DoNothing() *AliyunAvatarUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the AliyunAvatarCreate.OnConflict
// documentation for more info.
func (u *AliyunAvatarUpsertOne) Update(set func(*AliyunAvatarUpsert)) *AliyunAvatarUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&AliyunAvatarUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *AliyunAvatarUpsertOne) SetUpdatedAt(v time.Time) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateUpdatedAt() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetDeletedAt sets the "deleted_at" field.
func (u *AliyunAvatarUpsertOne) SetDeletedAt(v time.Time) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateDeletedAt() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *AliyunAvatarUpsertOne) ClearDeletedAt() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.ClearDeletedAt()
	})
}

// SetUserID sets the "user_id" field.
func (u *AliyunAvatarUpsertOne) SetUserID(v uint64) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetUserID(v)
	})
}

// AddUserID adds v to the "user_id" field.
func (u *AliyunAvatarUpsertOne) AddUserID(v uint64) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.AddUserID(v)
	})
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateUserID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateUserID()
	})
}

// SetBizID sets the "biz_id" field.
func (u *AliyunAvatarUpsertOne) SetBizID(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetBizID(v)
	})
}

// UpdateBizID sets the "biz_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateBizID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateBizID()
	})
}

// SetAccessKeyID sets the "access_key_id" field.
func (u *AliyunAvatarUpsertOne) SetAccessKeyID(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetAccessKeyID(v)
	})
}

// UpdateAccessKeyID sets the "access_key_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateAccessKeyID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateAccessKeyID()
	})
}

// SetAccessKeySecret sets the "access_key_secret" field.
func (u *AliyunAvatarUpsertOne) SetAccessKeySecret(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetAccessKeySecret(v)
	})
}

// UpdateAccessKeySecret sets the "access_key_secret" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateAccessKeySecret() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateAccessKeySecret()
	})
}

// SetAppID sets the "app_id" field.
func (u *AliyunAvatarUpsertOne) SetAppID(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetAppID(v)
	})
}

// UpdateAppID sets the "app_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateAppID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateAppID()
	})
}

// ClearAppID clears the value of the "app_id" field.
func (u *AliyunAvatarUpsertOne) ClearAppID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.ClearAppID()
	})
}

// SetTenantID sets the "tenant_id" field.
func (u *AliyunAvatarUpsertOne) SetTenantID(v uint64) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetTenantID(v)
	})
}

// AddTenantID adds v to the "tenant_id" field.
func (u *AliyunAvatarUpsertOne) AddTenantID(v uint64) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.AddTenantID(v)
	})
}

// UpdateTenantID sets the "tenant_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateTenantID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateTenantID()
	})
}

// SetResponse sets the "response" field.
func (u *AliyunAvatarUpsertOne) SetResponse(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetResponse(v)
	})
}

// UpdateResponse sets the "response" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateResponse() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateResponse()
	})
}

// SetToken sets the "token" field.
func (u *AliyunAvatarUpsertOne) SetToken(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetToken(v)
	})
}

// UpdateToken sets the "token" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateToken() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateToken()
	})
}

// SetSessionID sets the "session_id" field.
func (u *AliyunAvatarUpsertOne) SetSessionID(v string) *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetSessionID(v)
	})
}

// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertOne) UpdateSessionID() *AliyunAvatarUpsertOne {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateSessionID()
	})
}

// Exec executes the query.
func (u *AliyunAvatarUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for AliyunAvatarCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

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

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *AliyunAvatarUpsertOne) ID(ctx context.Context) (id uint64, err error) {
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *AliyunAvatarUpsertOne) IDX(ctx context.Context) uint64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// AliyunAvatarCreateBulk is the builder for creating many AliyunAvatar entities in bulk.
type AliyunAvatarCreateBulk struct {
	config
	err      error
	builders []*AliyunAvatarCreate
	conflict []sql.ConflictOption
}

// Save creates the AliyunAvatar entities in the database.
func (aacb *AliyunAvatarCreateBulk) Save(ctx context.Context) ([]*AliyunAvatar, error) {
	if aacb.err != nil {
		return nil, aacb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(aacb.builders))
	nodes := make([]*AliyunAvatar, len(aacb.builders))
	mutators := make([]Mutator, len(aacb.builders))
	for i := range aacb.builders {
		func(i int, root context.Context) {
			builder := aacb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*AliyunAvatarMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, aacb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = aacb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, aacb.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = uint64(id)
				}
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, aacb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (aacb *AliyunAvatarCreateBulk) SaveX(ctx context.Context) []*AliyunAvatar {
	v, err := aacb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.AliyunAvatar.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.AliyunAvatarUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (aacb *AliyunAvatarCreateBulk) OnConflict(opts ...sql.ConflictOption) *AliyunAvatarUpsertBulk {
	aacb.conflict = opts
	return &AliyunAvatarUpsertBulk{
		create: aacb,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.AliyunAvatar.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (aacb *AliyunAvatarCreateBulk) OnConflictColumns(columns ...string) *AliyunAvatarUpsertBulk {
	aacb.conflict = append(aacb.conflict, sql.ConflictColumns(columns...))
	return &AliyunAvatarUpsertBulk{
		create: aacb,
	}
}

// AliyunAvatarUpsertBulk is the builder for "upsert"-ing
// a bulk of AliyunAvatar nodes.
type AliyunAvatarUpsertBulk struct {
	create *AliyunAvatarCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.AliyunAvatar.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(aliyunavatar.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *AliyunAvatarUpsertBulk) UpdateNewValues() *AliyunAvatarUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(aliyunavatar.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(aliyunavatar.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.AliyunAvatar.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *AliyunAvatarUpsertBulk) Ignore() *AliyunAvatarUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *AliyunAvatarUpsertBulk) DoNothing() *AliyunAvatarUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the AliyunAvatarCreateBulk.OnConflict
// documentation for more info.
func (u *AliyunAvatarUpsertBulk) Update(set func(*AliyunAvatarUpsert)) *AliyunAvatarUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&AliyunAvatarUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *AliyunAvatarUpsertBulk) SetUpdatedAt(v time.Time) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateUpdatedAt() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetDeletedAt sets the "deleted_at" field.
func (u *AliyunAvatarUpsertBulk) SetDeletedAt(v time.Time) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateDeletedAt() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *AliyunAvatarUpsertBulk) ClearDeletedAt() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.ClearDeletedAt()
	})
}

// SetUserID sets the "user_id" field.
func (u *AliyunAvatarUpsertBulk) SetUserID(v uint64) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetUserID(v)
	})
}

// AddUserID adds v to the "user_id" field.
func (u *AliyunAvatarUpsertBulk) AddUserID(v uint64) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.AddUserID(v)
	})
}

// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateUserID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateUserID()
	})
}

// SetBizID sets the "biz_id" field.
func (u *AliyunAvatarUpsertBulk) SetBizID(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetBizID(v)
	})
}

// UpdateBizID sets the "biz_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateBizID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateBizID()
	})
}

// SetAccessKeyID sets the "access_key_id" field.
func (u *AliyunAvatarUpsertBulk) SetAccessKeyID(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetAccessKeyID(v)
	})
}

// UpdateAccessKeyID sets the "access_key_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateAccessKeyID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateAccessKeyID()
	})
}

// SetAccessKeySecret sets the "access_key_secret" field.
func (u *AliyunAvatarUpsertBulk) SetAccessKeySecret(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetAccessKeySecret(v)
	})
}

// UpdateAccessKeySecret sets the "access_key_secret" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateAccessKeySecret() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateAccessKeySecret()
	})
}

// SetAppID sets the "app_id" field.
func (u *AliyunAvatarUpsertBulk) SetAppID(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetAppID(v)
	})
}

// UpdateAppID sets the "app_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateAppID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateAppID()
	})
}

// ClearAppID clears the value of the "app_id" field.
func (u *AliyunAvatarUpsertBulk) ClearAppID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.ClearAppID()
	})
}

// SetTenantID sets the "tenant_id" field.
func (u *AliyunAvatarUpsertBulk) SetTenantID(v uint64) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetTenantID(v)
	})
}

// AddTenantID adds v to the "tenant_id" field.
func (u *AliyunAvatarUpsertBulk) AddTenantID(v uint64) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.AddTenantID(v)
	})
}

// UpdateTenantID sets the "tenant_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateTenantID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateTenantID()
	})
}

// SetResponse sets the "response" field.
func (u *AliyunAvatarUpsertBulk) SetResponse(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetResponse(v)
	})
}

// UpdateResponse sets the "response" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateResponse() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateResponse()
	})
}

// SetToken sets the "token" field.
func (u *AliyunAvatarUpsertBulk) SetToken(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetToken(v)
	})
}

// UpdateToken sets the "token" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateToken() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateToken()
	})
}

// SetSessionID sets the "session_id" field.
func (u *AliyunAvatarUpsertBulk) SetSessionID(v string) *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.SetSessionID(v)
	})
}

// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *AliyunAvatarUpsertBulk) UpdateSessionID() *AliyunAvatarUpsertBulk {
	return u.Update(func(s *AliyunAvatarUpsert) {
		s.UpdateSessionID()
	})
}

// Exec executes the query.
func (u *AliyunAvatarUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AliyunAvatarCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for AliyunAvatarCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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