// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WxCardCreate is the builder for creating a WxCard entity.
type WxCardCreate struct {
	config
	mutation *WxCardMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

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

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

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

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableUserID(u *uint64) *WxCardCreate {
	if u != nil {
		wcc.SetUserID(*u)
	}
	return wcc
}

// SetWxUserID sets the "wx_user_id" field.
func (wcc *WxCardCreate) SetWxUserID(u uint64) *WxCardCreate {
	wcc.mutation.SetWxUserID(u)
	return wcc
}

// SetNillableWxUserID sets the "wx_user_id" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableWxUserID(u *uint64) *WxCardCreate {
	if u != nil {
		wcc.SetWxUserID(*u)
	}
	return wcc
}

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

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

// SetLogo sets the "logo" field.
func (wcc *WxCardCreate) SetLogo(s string) *WxCardCreate {
	wcc.mutation.SetLogo(s)
	return wcc
}

// SetNillableLogo sets the "logo" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableLogo(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetLogo(*s)
	}
	return wcc
}

// SetName sets the "name" field.
func (wcc *WxCardCreate) SetName(s string) *WxCardCreate {
	wcc.mutation.SetName(s)
	return wcc
}

// SetNillableName sets the "name" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableName(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetName(*s)
	}
	return wcc
}

// SetCompany sets the "company" field.
func (wcc *WxCardCreate) SetCompany(s string) *WxCardCreate {
	wcc.mutation.SetCompany(s)
	return wcc
}

// SetNillableCompany sets the "company" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableCompany(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetCompany(*s)
	}
	return wcc
}

// SetAddress sets the "address" field.
func (wcc *WxCardCreate) SetAddress(s string) *WxCardCreate {
	wcc.mutation.SetAddress(s)
	return wcc
}

// SetNillableAddress sets the "address" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableAddress(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetAddress(*s)
	}
	return wcc
}

// SetPhone sets the "phone" field.
func (wcc *WxCardCreate) SetPhone(s string) *WxCardCreate {
	wcc.mutation.SetPhone(s)
	return wcc
}

// SetNillablePhone sets the "phone" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillablePhone(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetPhone(*s)
	}
	return wcc
}

// SetOfficialAccount sets the "official_account" field.
func (wcc *WxCardCreate) SetOfficialAccount(s string) *WxCardCreate {
	wcc.mutation.SetOfficialAccount(s)
	return wcc
}

// SetNillableOfficialAccount sets the "official_account" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableOfficialAccount(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetOfficialAccount(*s)
	}
	return wcc
}

// SetWechatAccount sets the "wechat_account" field.
func (wcc *WxCardCreate) SetWechatAccount(s string) *WxCardCreate {
	wcc.mutation.SetWechatAccount(s)
	return wcc
}

// SetNillableWechatAccount sets the "wechat_account" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableWechatAccount(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetWechatAccount(*s)
	}
	return wcc
}

// SetEmail sets the "email" field.
func (wcc *WxCardCreate) SetEmail(s string) *WxCardCreate {
	wcc.mutation.SetEmail(s)
	return wcc
}

// SetNillableEmail sets the "email" field if the given value is not nil.
func (wcc *WxCardCreate) SetNillableEmail(s *string) *WxCardCreate {
	if s != nil {
		wcc.SetEmail(*s)
	}
	return wcc
}

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

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

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

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

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

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

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

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

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

// Mutation returns the WxCardMutation object of the builder.
func (wcc *WxCardCreate) Mutation() *WxCardMutation {
	return wcc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (wcc *WxCardCreate) defaults() error {
	if _, ok := wcc.mutation.CreatedAt(); !ok {
		if wxcard.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized wxcard.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := wxcard.DefaultCreatedAt()
		wcc.mutation.SetCreatedAt(v)
	}
	if _, ok := wcc.mutation.UpdatedAt(); !ok {
		if wxcard.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized wxcard.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := wxcard.DefaultUpdatedAt()
		wcc.mutation.SetUpdatedAt(v)
	}
	if _, ok := wcc.mutation.UserID(); !ok {
		v := wxcard.DefaultUserID
		wcc.mutation.SetUserID(v)
	}
	if _, ok := wcc.mutation.WxUserID(); !ok {
		v := wxcard.DefaultWxUserID
		wcc.mutation.SetWxUserID(v)
	}
	if _, ok := wcc.mutation.Avatar(); !ok {
		v := wxcard.DefaultAvatar
		wcc.mutation.SetAvatar(v)
	}
	if _, ok := wcc.mutation.Logo(); !ok {
		v := wxcard.DefaultLogo
		wcc.mutation.SetLogo(v)
	}
	if _, ok := wcc.mutation.Name(); !ok {
		v := wxcard.DefaultName
		wcc.mutation.SetName(v)
	}
	if _, ok := wcc.mutation.Company(); !ok {
		v := wxcard.DefaultCompany
		wcc.mutation.SetCompany(v)
	}
	if _, ok := wcc.mutation.Address(); !ok {
		v := wxcard.DefaultAddress
		wcc.mutation.SetAddress(v)
	}
	if _, ok := wcc.mutation.Phone(); !ok {
		v := wxcard.DefaultPhone
		wcc.mutation.SetPhone(v)
	}
	if _, ok := wcc.mutation.OfficialAccount(); !ok {
		v := wxcard.DefaultOfficialAccount
		wcc.mutation.SetOfficialAccount(v)
	}
	if _, ok := wcc.mutation.WechatAccount(); !ok {
		v := wxcard.DefaultWechatAccount
		wcc.mutation.SetWechatAccount(v)
	}
	if _, ok := wcc.mutation.Email(); !ok {
		v := wxcard.DefaultEmail
		wcc.mutation.SetEmail(v)
	}
	if _, ok := wcc.mutation.Intro(); !ok {
		v := wxcard.DefaultIntro
		wcc.mutation.SetIntro(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (wcc *WxCardCreate) check() error {
	if _, ok := wcc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WxCard.created_at"`)}
	}
	if _, ok := wcc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WxCard.updated_at"`)}
	}
	if _, ok := wcc.mutation.Avatar(); !ok {
		return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "WxCard.avatar"`)}
	}
	if _, ok := wcc.mutation.Logo(); !ok {
		return &ValidationError{Name: "logo", err: errors.New(`ent: missing required field "WxCard.logo"`)}
	}
	if _, ok := wcc.mutation.Name(); !ok {
		return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "WxCard.name"`)}
	}
	if _, ok := wcc.mutation.Company(); !ok {
		return &ValidationError{Name: "company", err: errors.New(`ent: missing required field "WxCard.company"`)}
	}
	if _, ok := wcc.mutation.Address(); !ok {
		return &ValidationError{Name: "address", err: errors.New(`ent: missing required field "WxCard.address"`)}
	}
	if _, ok := wcc.mutation.Phone(); !ok {
		return &ValidationError{Name: "phone", err: errors.New(`ent: missing required field "WxCard.phone"`)}
	}
	if _, ok := wcc.mutation.OfficialAccount(); !ok {
		return &ValidationError{Name: "official_account", err: errors.New(`ent: missing required field "WxCard.official_account"`)}
	}
	if _, ok := wcc.mutation.WechatAccount(); !ok {
		return &ValidationError{Name: "wechat_account", err: errors.New(`ent: missing required field "WxCard.wechat_account"`)}
	}
	return nil
}

func (wcc *WxCardCreate) sqlSave(ctx context.Context) (*WxCard, error) {
	if err := wcc.check(); err != nil {
		return nil, err
	}
	_node, _spec := wcc.createSpec()
	if err := sqlgraph.CreateNode(ctx, wcc.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)
	}
	wcc.mutation.id = &_node.ID
	wcc.mutation.done = true
	return _node, nil
}

func (wcc *WxCardCreate) createSpec() (*WxCard, *sqlgraph.CreateSpec) {
	var (
		_node = &WxCard{config: wcc.config}
		_spec = sqlgraph.NewCreateSpec(wxcard.Table, sqlgraph.NewFieldSpec(wxcard.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = wcc.conflict
	if id, ok := wcc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := wcc.mutation.CreatedAt(); ok {
		_spec.SetField(wxcard.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := wcc.mutation.UpdatedAt(); ok {
		_spec.SetField(wxcard.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := wcc.mutation.DeletedAt(); ok {
		_spec.SetField(wxcard.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := wcc.mutation.UserID(); ok {
		_spec.SetField(wxcard.FieldUserID, field.TypeUint64, value)
		_node.UserID = value
	}
	if value, ok := wcc.mutation.WxUserID(); ok {
		_spec.SetField(wxcard.FieldWxUserID, field.TypeUint64, value)
		_node.WxUserID = value
	}
	if value, ok := wcc.mutation.Avatar(); ok {
		_spec.SetField(wxcard.FieldAvatar, field.TypeString, value)
		_node.Avatar = value
	}
	if value, ok := wcc.mutation.Logo(); ok {
		_spec.SetField(wxcard.FieldLogo, field.TypeString, value)
		_node.Logo = value
	}
	if value, ok := wcc.mutation.Name(); ok {
		_spec.SetField(wxcard.FieldName, field.TypeString, value)
		_node.Name = value
	}
	if value, ok := wcc.mutation.Company(); ok {
		_spec.SetField(wxcard.FieldCompany, field.TypeString, value)
		_node.Company = value
	}
	if value, ok := wcc.mutation.Address(); ok {
		_spec.SetField(wxcard.FieldAddress, field.TypeString, value)
		_node.Address = value
	}
	if value, ok := wcc.mutation.Phone(); ok {
		_spec.SetField(wxcard.FieldPhone, field.TypeString, value)
		_node.Phone = value
	}
	if value, ok := wcc.mutation.OfficialAccount(); ok {
		_spec.SetField(wxcard.FieldOfficialAccount, field.TypeString, value)
		_node.OfficialAccount = value
	}
	if value, ok := wcc.mutation.WechatAccount(); ok {
		_spec.SetField(wxcard.FieldWechatAccount, field.TypeString, value)
		_node.WechatAccount = value
	}
	if value, ok := wcc.mutation.Email(); ok {
		_spec.SetField(wxcard.FieldEmail, field.TypeString, value)
		_node.Email = value
	}
	if value, ok := wcc.mutation.APIBase(); ok {
		_spec.SetField(wxcard.FieldAPIBase, field.TypeString, value)
		_node.APIBase = value
	}
	if value, ok := wcc.mutation.APIKey(); ok {
		_spec.SetField(wxcard.FieldAPIKey, field.TypeString, value)
		_node.APIKey = value
	}
	if value, ok := wcc.mutation.AiInfo(); ok {
		_spec.SetField(wxcard.FieldAiInfo, field.TypeString, value)
		_node.AiInfo = value
	}
	if value, ok := wcc.mutation.Intro(); ok {
		_spec.SetField(wxcard.FieldIntro, field.TypeString, value)
		_node.Intro = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WxCard.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.WxCardUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (wcc *WxCardCreate) OnConflict(opts ...sql.ConflictOption) *WxCardUpsertOne {
	wcc.conflict = opts
	return &WxCardUpsertOne{
		create: wcc,
	}
}

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

type (
	// WxCardUpsertOne is the builder for "upsert"-ing
	//  one WxCard node.
	WxCardUpsertOne struct {
		create *WxCardCreate
	}

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

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

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

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

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

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

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

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

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

// ClearUserID clears the value of the "user_id" field.
func (u *WxCardUpsert) ClearUserID() *WxCardUpsert {
	u.SetNull(wxcard.FieldUserID)
	return u
}

// SetWxUserID sets the "wx_user_id" field.
func (u *WxCardUpsert) SetWxUserID(v uint64) *WxCardUpsert {
	u.Set(wxcard.FieldWxUserID, v)
	return u
}

// UpdateWxUserID sets the "wx_user_id" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateWxUserID() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldWxUserID)
	return u
}

// AddWxUserID adds v to the "wx_user_id" field.
func (u *WxCardUpsert) AddWxUserID(v uint64) *WxCardUpsert {
	u.Add(wxcard.FieldWxUserID, v)
	return u
}

// ClearWxUserID clears the value of the "wx_user_id" field.
func (u *WxCardUpsert) ClearWxUserID() *WxCardUpsert {
	u.SetNull(wxcard.FieldWxUserID)
	return u
}

// SetAvatar sets the "avatar" field.
func (u *WxCardUpsert) SetAvatar(v string) *WxCardUpsert {
	u.Set(wxcard.FieldAvatar, v)
	return u
}

// UpdateAvatar sets the "avatar" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateAvatar() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldAvatar)
	return u
}

// SetLogo sets the "logo" field.
func (u *WxCardUpsert) SetLogo(v string) *WxCardUpsert {
	u.Set(wxcard.FieldLogo, v)
	return u
}

// UpdateLogo sets the "logo" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateLogo() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldLogo)
	return u
}

// SetName sets the "name" field.
func (u *WxCardUpsert) SetName(v string) *WxCardUpsert {
	u.Set(wxcard.FieldName, v)
	return u
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateName() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldName)
	return u
}

// SetCompany sets the "company" field.
func (u *WxCardUpsert) SetCompany(v string) *WxCardUpsert {
	u.Set(wxcard.FieldCompany, v)
	return u
}

// UpdateCompany sets the "company" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateCompany() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldCompany)
	return u
}

// SetAddress sets the "address" field.
func (u *WxCardUpsert) SetAddress(v string) *WxCardUpsert {
	u.Set(wxcard.FieldAddress, v)
	return u
}

// UpdateAddress sets the "address" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateAddress() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldAddress)
	return u
}

// SetPhone sets the "phone" field.
func (u *WxCardUpsert) SetPhone(v string) *WxCardUpsert {
	u.Set(wxcard.FieldPhone, v)
	return u
}

// UpdatePhone sets the "phone" field to the value that was provided on create.
func (u *WxCardUpsert) UpdatePhone() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldPhone)
	return u
}

// SetOfficialAccount sets the "official_account" field.
func (u *WxCardUpsert) SetOfficialAccount(v string) *WxCardUpsert {
	u.Set(wxcard.FieldOfficialAccount, v)
	return u
}

// UpdateOfficialAccount sets the "official_account" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateOfficialAccount() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldOfficialAccount)
	return u
}

// SetWechatAccount sets the "wechat_account" field.
func (u *WxCardUpsert) SetWechatAccount(v string) *WxCardUpsert {
	u.Set(wxcard.FieldWechatAccount, v)
	return u
}

// UpdateWechatAccount sets the "wechat_account" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateWechatAccount() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldWechatAccount)
	return u
}

// SetEmail sets the "email" field.
func (u *WxCardUpsert) SetEmail(v string) *WxCardUpsert {
	u.Set(wxcard.FieldEmail, v)
	return u
}

// UpdateEmail sets the "email" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateEmail() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldEmail)
	return u
}

// ClearEmail clears the value of the "email" field.
func (u *WxCardUpsert) ClearEmail() *WxCardUpsert {
	u.SetNull(wxcard.FieldEmail)
	return u
}

// SetAPIBase sets the "api_base" field.
func (u *WxCardUpsert) SetAPIBase(v string) *WxCardUpsert {
	u.Set(wxcard.FieldAPIBase, v)
	return u
}

// UpdateAPIBase sets the "api_base" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateAPIBase() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldAPIBase)
	return u
}

// ClearAPIBase clears the value of the "api_base" field.
func (u *WxCardUpsert) ClearAPIBase() *WxCardUpsert {
	u.SetNull(wxcard.FieldAPIBase)
	return u
}

// SetAPIKey sets the "api_key" field.
func (u *WxCardUpsert) SetAPIKey(v string) *WxCardUpsert {
	u.Set(wxcard.FieldAPIKey, v)
	return u
}

// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateAPIKey() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldAPIKey)
	return u
}

// ClearAPIKey clears the value of the "api_key" field.
func (u *WxCardUpsert) ClearAPIKey() *WxCardUpsert {
	u.SetNull(wxcard.FieldAPIKey)
	return u
}

// SetAiInfo sets the "ai_info" field.
func (u *WxCardUpsert) SetAiInfo(v string) *WxCardUpsert {
	u.Set(wxcard.FieldAiInfo, v)
	return u
}

// UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateAiInfo() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldAiInfo)
	return u
}

// ClearAiInfo clears the value of the "ai_info" field.
func (u *WxCardUpsert) ClearAiInfo() *WxCardUpsert {
	u.SetNull(wxcard.FieldAiInfo)
	return u
}

// SetIntro sets the "intro" field.
func (u *WxCardUpsert) SetIntro(v string) *WxCardUpsert {
	u.Set(wxcard.FieldIntro, v)
	return u
}

// UpdateIntro sets the "intro" field to the value that was provided on create.
func (u *WxCardUpsert) UpdateIntro() *WxCardUpsert {
	u.SetExcluded(wxcard.FieldIntro)
	return u
}

// ClearIntro clears the value of the "intro" field.
func (u *WxCardUpsert) ClearIntro() *WxCardUpsert {
	u.SetNull(wxcard.FieldIntro)
	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.WxCard.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(wxcard.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WxCardUpsertOne) UpdateNewValues() *WxCardUpsertOne {
	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(wxcard.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(wxcard.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.WxCard.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *WxCardUpsertOne) Ignore() *WxCardUpsertOne {
	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 *WxCardUpsertOne) DoNothing() *WxCardUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

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

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

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

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

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

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

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

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

// ClearUserID clears the value of the "user_id" field.
func (u *WxCardUpsertOne) ClearUserID() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearUserID()
	})
}

// SetWxUserID sets the "wx_user_id" field.
func (u *WxCardUpsertOne) SetWxUserID(v uint64) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetWxUserID(v)
	})
}

// AddWxUserID adds v to the "wx_user_id" field.
func (u *WxCardUpsertOne) AddWxUserID(v uint64) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.AddWxUserID(v)
	})
}

// UpdateWxUserID sets the "wx_user_id" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateWxUserID() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateWxUserID()
	})
}

// ClearWxUserID clears the value of the "wx_user_id" field.
func (u *WxCardUpsertOne) ClearWxUserID() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearWxUserID()
	})
}

// SetAvatar sets the "avatar" field.
func (u *WxCardUpsertOne) SetAvatar(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAvatar(v)
	})
}

// UpdateAvatar sets the "avatar" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateAvatar() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAvatar()
	})
}

// SetLogo sets the "logo" field.
func (u *WxCardUpsertOne) SetLogo(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetLogo(v)
	})
}

// UpdateLogo sets the "logo" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateLogo() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateLogo()
	})
}

// SetName sets the "name" field.
func (u *WxCardUpsertOne) SetName(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateName() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateName()
	})
}

// SetCompany sets the "company" field.
func (u *WxCardUpsertOne) SetCompany(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetCompany(v)
	})
}

// UpdateCompany sets the "company" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateCompany() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateCompany()
	})
}

// SetAddress sets the "address" field.
func (u *WxCardUpsertOne) SetAddress(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAddress(v)
	})
}

// UpdateAddress sets the "address" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateAddress() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAddress()
	})
}

// SetPhone sets the "phone" field.
func (u *WxCardUpsertOne) SetPhone(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetPhone(v)
	})
}

// UpdatePhone sets the "phone" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdatePhone() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdatePhone()
	})
}

// SetOfficialAccount sets the "official_account" field.
func (u *WxCardUpsertOne) SetOfficialAccount(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetOfficialAccount(v)
	})
}

// UpdateOfficialAccount sets the "official_account" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateOfficialAccount() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateOfficialAccount()
	})
}

// SetWechatAccount sets the "wechat_account" field.
func (u *WxCardUpsertOne) SetWechatAccount(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetWechatAccount(v)
	})
}

// UpdateWechatAccount sets the "wechat_account" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateWechatAccount() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateWechatAccount()
	})
}

// SetEmail sets the "email" field.
func (u *WxCardUpsertOne) SetEmail(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetEmail(v)
	})
}

// UpdateEmail sets the "email" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateEmail() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateEmail()
	})
}

// ClearEmail clears the value of the "email" field.
func (u *WxCardUpsertOne) ClearEmail() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearEmail()
	})
}

// SetAPIBase sets the "api_base" field.
func (u *WxCardUpsertOne) SetAPIBase(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAPIBase(v)
	})
}

// UpdateAPIBase sets the "api_base" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateAPIBase() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAPIBase()
	})
}

// ClearAPIBase clears the value of the "api_base" field.
func (u *WxCardUpsertOne) ClearAPIBase() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearAPIBase()
	})
}

// SetAPIKey sets the "api_key" field.
func (u *WxCardUpsertOne) SetAPIKey(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAPIKey(v)
	})
}

// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateAPIKey() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAPIKey()
	})
}

// ClearAPIKey clears the value of the "api_key" field.
func (u *WxCardUpsertOne) ClearAPIKey() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearAPIKey()
	})
}

// SetAiInfo sets the "ai_info" field.
func (u *WxCardUpsertOne) SetAiInfo(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAiInfo(v)
	})
}

// UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateAiInfo() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAiInfo()
	})
}

// ClearAiInfo clears the value of the "ai_info" field.
func (u *WxCardUpsertOne) ClearAiInfo() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearAiInfo()
	})
}

// SetIntro sets the "intro" field.
func (u *WxCardUpsertOne) SetIntro(v string) *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.SetIntro(v)
	})
}

// UpdateIntro sets the "intro" field to the value that was provided on create.
func (u *WxCardUpsertOne) UpdateIntro() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateIntro()
	})
}

// ClearIntro clears the value of the "intro" field.
func (u *WxCardUpsertOne) ClearIntro() *WxCardUpsertOne {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearIntro()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *WxCardUpsertOne) 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 *WxCardUpsertOne) 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 *WxCardUpsertOne) IDX(ctx context.Context) uint64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

// Save creates the WxCard entities in the database.
func (wccb *WxCardCreateBulk) Save(ctx context.Context) ([]*WxCard, error) {
	if wccb.err != nil {
		return nil, wccb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(wccb.builders))
	nodes := make([]*WxCard, len(wccb.builders))
	mutators := make([]Mutator, len(wccb.builders))
	for i := range wccb.builders {
		func(i int, root context.Context) {
			builder := wccb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*WxCardMutation)
				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, wccb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = wccb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, wccb.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, wccb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WxCard.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.WxCardUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (wccb *WxCardCreateBulk) OnConflict(opts ...sql.ConflictOption) *WxCardUpsertBulk {
	wccb.conflict = opts
	return &WxCardUpsertBulk{
		create: wccb,
	}
}

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

// WxCardUpsertBulk is the builder for "upsert"-ing
// a bulk of WxCard nodes.
type WxCardUpsertBulk struct {
	create *WxCardCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.WxCard.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(wxcard.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WxCardUpsertBulk) UpdateNewValues() *WxCardUpsertBulk {
	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(wxcard.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(wxcard.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.WxCard.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *WxCardUpsertBulk) Ignore() *WxCardUpsertBulk {
	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 *WxCardUpsertBulk) DoNothing() *WxCardUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

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

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

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

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

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

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

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

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

// ClearUserID clears the value of the "user_id" field.
func (u *WxCardUpsertBulk) ClearUserID() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearUserID()
	})
}

// SetWxUserID sets the "wx_user_id" field.
func (u *WxCardUpsertBulk) SetWxUserID(v uint64) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetWxUserID(v)
	})
}

// AddWxUserID adds v to the "wx_user_id" field.
func (u *WxCardUpsertBulk) AddWxUserID(v uint64) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.AddWxUserID(v)
	})
}

// UpdateWxUserID sets the "wx_user_id" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateWxUserID() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateWxUserID()
	})
}

// ClearWxUserID clears the value of the "wx_user_id" field.
func (u *WxCardUpsertBulk) ClearWxUserID() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearWxUserID()
	})
}

// SetAvatar sets the "avatar" field.
func (u *WxCardUpsertBulk) SetAvatar(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAvatar(v)
	})
}

// UpdateAvatar sets the "avatar" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateAvatar() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAvatar()
	})
}

// SetLogo sets the "logo" field.
func (u *WxCardUpsertBulk) SetLogo(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetLogo(v)
	})
}

// UpdateLogo sets the "logo" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateLogo() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateLogo()
	})
}

// SetName sets the "name" field.
func (u *WxCardUpsertBulk) SetName(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateName() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateName()
	})
}

// SetCompany sets the "company" field.
func (u *WxCardUpsertBulk) SetCompany(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetCompany(v)
	})
}

// UpdateCompany sets the "company" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateCompany() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateCompany()
	})
}

// SetAddress sets the "address" field.
func (u *WxCardUpsertBulk) SetAddress(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAddress(v)
	})
}

// UpdateAddress sets the "address" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateAddress() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAddress()
	})
}

// SetPhone sets the "phone" field.
func (u *WxCardUpsertBulk) SetPhone(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetPhone(v)
	})
}

// UpdatePhone sets the "phone" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdatePhone() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdatePhone()
	})
}

// SetOfficialAccount sets the "official_account" field.
func (u *WxCardUpsertBulk) SetOfficialAccount(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetOfficialAccount(v)
	})
}

// UpdateOfficialAccount sets the "official_account" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateOfficialAccount() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateOfficialAccount()
	})
}

// SetWechatAccount sets the "wechat_account" field.
func (u *WxCardUpsertBulk) SetWechatAccount(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetWechatAccount(v)
	})
}

// UpdateWechatAccount sets the "wechat_account" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateWechatAccount() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateWechatAccount()
	})
}

// SetEmail sets the "email" field.
func (u *WxCardUpsertBulk) SetEmail(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetEmail(v)
	})
}

// UpdateEmail sets the "email" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateEmail() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateEmail()
	})
}

// ClearEmail clears the value of the "email" field.
func (u *WxCardUpsertBulk) ClearEmail() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearEmail()
	})
}

// SetAPIBase sets the "api_base" field.
func (u *WxCardUpsertBulk) SetAPIBase(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAPIBase(v)
	})
}

// UpdateAPIBase sets the "api_base" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateAPIBase() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAPIBase()
	})
}

// ClearAPIBase clears the value of the "api_base" field.
func (u *WxCardUpsertBulk) ClearAPIBase() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearAPIBase()
	})
}

// SetAPIKey sets the "api_key" field.
func (u *WxCardUpsertBulk) SetAPIKey(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAPIKey(v)
	})
}

// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateAPIKey() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAPIKey()
	})
}

// ClearAPIKey clears the value of the "api_key" field.
func (u *WxCardUpsertBulk) ClearAPIKey() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearAPIKey()
	})
}

// SetAiInfo sets the "ai_info" field.
func (u *WxCardUpsertBulk) SetAiInfo(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetAiInfo(v)
	})
}

// UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateAiInfo() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateAiInfo()
	})
}

// ClearAiInfo clears the value of the "ai_info" field.
func (u *WxCardUpsertBulk) ClearAiInfo() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearAiInfo()
	})
}

// SetIntro sets the "intro" field.
func (u *WxCardUpsertBulk) SetIntro(v string) *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.SetIntro(v)
	})
}

// UpdateIntro sets the "intro" field to the value that was provided on create.
func (u *WxCardUpsertBulk) UpdateIntro() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.UpdateIntro()
	})
}

// ClearIntro clears the value of the "intro" field.
func (u *WxCardUpsertBulk) ClearIntro() *WxCardUpsertBulk {
	return u.Update(func(s *WxCardUpsert) {
		s.ClearIntro()
	})
}

// Exec executes the query.
func (u *WxCardUpsertBulk) 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 WxCardCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for WxCardCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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