// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WhatsappCreate is the builder for creating a Whatsapp entity.
type WhatsappCreate struct {
	config
	mutation *WhatsappMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetStatus sets the "status" field.
func (wc *WhatsappCreate) SetStatus(u uint8) *WhatsappCreate {
	wc.mutation.SetStatus(u)
	return wc
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableStatus(u *uint8) *WhatsappCreate {
	if u != nil {
		wc.SetStatus(*u)
	}
	return wc
}

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

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

// SetWaID sets the "wa_id" field.
func (wc *WhatsappCreate) SetWaID(s string) *WhatsappCreate {
	wc.mutation.SetWaID(s)
	return wc
}

// SetNillableWaID sets the "wa_id" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableWaID(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetWaID(*s)
	}
	return wc
}

// SetWaName sets the "wa_name" field.
func (wc *WhatsappCreate) SetWaName(s string) *WhatsappCreate {
	wc.mutation.SetWaName(s)
	return wc
}

// SetNillableWaName sets the "wa_name" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableWaName(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetWaName(*s)
	}
	return wc
}

// SetCallback sets the "callback" field.
func (wc *WhatsappCreate) SetCallback(s string) *WhatsappCreate {
	wc.mutation.SetCallback(s)
	return wc
}

// SetNillableCallback sets the "callback" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableCallback(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetCallback(*s)
	}
	return wc
}

// SetAgentID sets the "agent_id" field.
func (wc *WhatsappCreate) SetAgentID(u uint64) *WhatsappCreate {
	wc.mutation.SetAgentID(u)
	return wc
}

// SetNillableAgentID sets the "agent_id" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableAgentID(u *uint64) *WhatsappCreate {
	if u != nil {
		wc.SetAgentID(*u)
	}
	return wc
}

// SetAccount sets the "account" field.
func (wc *WhatsappCreate) SetAccount(s string) *WhatsappCreate {
	wc.mutation.SetAccount(s)
	return wc
}

// SetNillableAccount sets the "account" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableAccount(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetAccount(*s)
	}
	return wc
}

// SetCc sets the "cc" field.
func (wc *WhatsappCreate) SetCc(s string) *WhatsappCreate {
	wc.mutation.SetCc(s)
	return wc
}

// SetNillableCc sets the "cc" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableCc(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetCc(*s)
	}
	return wc
}

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

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

// SetCcPhone sets the "cc_phone" field.
func (wc *WhatsappCreate) SetCcPhone(s string) *WhatsappCreate {
	wc.mutation.SetCcPhone(s)
	return wc
}

// SetNillableCcPhone sets the "cc_phone" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillableCcPhone(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetCcPhone(*s)
	}
	return wc
}

// SetPhoneName sets the "phone_name" field.
func (wc *WhatsappCreate) SetPhoneName(s string) *WhatsappCreate {
	wc.mutation.SetPhoneName(s)
	return wc
}

// SetNillablePhoneName sets the "phone_name" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillablePhoneName(s *string) *WhatsappCreate {
	if s != nil {
		wc.SetPhoneName(*s)
	}
	return wc
}

// SetPhoneStatus sets the "phone_status" field.
func (wc *WhatsappCreate) SetPhoneStatus(i int8) *WhatsappCreate {
	wc.mutation.SetPhoneStatus(i)
	return wc
}

// SetNillablePhoneStatus sets the "phone_status" field if the given value is not nil.
func (wc *WhatsappCreate) SetNillablePhoneStatus(i *int8) *WhatsappCreate {
	if i != nil {
		wc.SetPhoneStatus(*i)
	}
	return wc
}

// SetOrganizationID sets the "organization_id" field.
func (wc *WhatsappCreate) SetOrganizationID(u uint64) *WhatsappCreate {
	wc.mutation.SetOrganizationID(u)
	return wc
}

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

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

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

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

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

// SetAllowList sets the "allow_list" field.
func (wc *WhatsappCreate) SetAllowList(s []string) *WhatsappCreate {
	wc.mutation.SetAllowList(s)
	return wc
}

// SetGroupAllowList sets the "group_allow_list" field.
func (wc *WhatsappCreate) SetGroupAllowList(s []string) *WhatsappCreate {
	wc.mutation.SetGroupAllowList(s)
	return wc
}

// SetBlockList sets the "block_list" field.
func (wc *WhatsappCreate) SetBlockList(s []string) *WhatsappCreate {
	wc.mutation.SetBlockList(s)
	return wc
}

// SetGroupBlockList sets the "group_block_list" field.
func (wc *WhatsappCreate) SetGroupBlockList(s []string) *WhatsappCreate {
	wc.mutation.SetGroupBlockList(s)
	return wc
}

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

// SetAgent sets the "agent" edge to the Agent entity.
func (wc *WhatsappCreate) SetAgent(a *Agent) *WhatsappCreate {
	return wc.SetAgentID(a.ID)
}

// Mutation returns the WhatsappMutation object of the builder.
func (wc *WhatsappCreate) Mutation() *WhatsappMutation {
	return wc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (wc *WhatsappCreate) defaults() error {
	if _, ok := wc.mutation.CreatedAt(); !ok {
		if whatsapp.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized whatsapp.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := whatsapp.DefaultCreatedAt()
		wc.mutation.SetCreatedAt(v)
	}
	if _, ok := wc.mutation.UpdatedAt(); !ok {
		if whatsapp.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized whatsapp.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := whatsapp.DefaultUpdatedAt()
		wc.mutation.SetUpdatedAt(v)
	}
	if _, ok := wc.mutation.Status(); !ok {
		v := whatsapp.DefaultStatus
		wc.mutation.SetStatus(v)
	}
	if _, ok := wc.mutation.WaID(); !ok {
		v := whatsapp.DefaultWaID
		wc.mutation.SetWaID(v)
	}
	if _, ok := wc.mutation.WaName(); !ok {
		v := whatsapp.DefaultWaName
		wc.mutation.SetWaName(v)
	}
	if _, ok := wc.mutation.Callback(); !ok {
		v := whatsapp.DefaultCallback
		wc.mutation.SetCallback(v)
	}
	if _, ok := wc.mutation.AgentID(); !ok {
		v := whatsapp.DefaultAgentID
		wc.mutation.SetAgentID(v)
	}
	if _, ok := wc.mutation.Account(); !ok {
		v := whatsapp.DefaultAccount
		wc.mutation.SetAccount(v)
	}
	if _, ok := wc.mutation.Cc(); !ok {
		v := whatsapp.DefaultCc
		wc.mutation.SetCc(v)
	}
	if _, ok := wc.mutation.Phone(); !ok {
		v := whatsapp.DefaultPhone
		wc.mutation.SetPhone(v)
	}
	if _, ok := wc.mutation.CcPhone(); !ok {
		v := whatsapp.DefaultCcPhone
		wc.mutation.SetCcPhone(v)
	}
	if _, ok := wc.mutation.PhoneName(); !ok {
		v := whatsapp.DefaultPhoneName
		wc.mutation.SetPhoneName(v)
	}
	if _, ok := wc.mutation.PhoneStatus(); !ok {
		v := whatsapp.DefaultPhoneStatus
		wc.mutation.SetPhoneStatus(v)
	}
	if _, ok := wc.mutation.OrganizationID(); !ok {
		v := whatsapp.DefaultOrganizationID
		wc.mutation.SetOrganizationID(v)
	}
	if _, ok := wc.mutation.APIBase(); !ok {
		v := whatsapp.DefaultAPIBase
		wc.mutation.SetAPIBase(v)
	}
	if _, ok := wc.mutation.APIKey(); !ok {
		v := whatsapp.DefaultAPIKey
		wc.mutation.SetAPIKey(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (wc *WhatsappCreate) check() error {
	if _, ok := wc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Whatsapp.created_at"`)}
	}
	if _, ok := wc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Whatsapp.updated_at"`)}
	}
	if _, ok := wc.mutation.AgentID(); !ok {
		return &ValidationError{Name: "agent_id", err: errors.New(`ent: missing required field "Whatsapp.agent_id"`)}
	}
	if _, ok := wc.mutation.Cc(); !ok {
		return &ValidationError{Name: "cc", err: errors.New(`ent: missing required field "Whatsapp.cc"`)}
	}
	if _, ok := wc.mutation.Phone(); !ok {
		return &ValidationError{Name: "phone", err: errors.New(`ent: missing required field "Whatsapp.phone"`)}
	}
	if _, ok := wc.mutation.CcPhone(); !ok {
		return &ValidationError{Name: "cc_phone", err: errors.New(`ent: missing required field "Whatsapp.cc_phone"`)}
	}
	if _, ok := wc.mutation.PhoneName(); !ok {
		return &ValidationError{Name: "phone_name", err: errors.New(`ent: missing required field "Whatsapp.phone_name"`)}
	}
	if _, ok := wc.mutation.PhoneStatus(); !ok {
		return &ValidationError{Name: "phone_status", err: errors.New(`ent: missing required field "Whatsapp.phone_status"`)}
	}
	if _, ok := wc.mutation.AgentID(); !ok {
		return &ValidationError{Name: "agent", err: errors.New(`ent: missing required edge "Whatsapp.agent"`)}
	}
	return nil
}

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

func (wc *WhatsappCreate) createSpec() (*Whatsapp, *sqlgraph.CreateSpec) {
	var (
		_node = &Whatsapp{config: wc.config}
		_spec = sqlgraph.NewCreateSpec(whatsapp.Table, sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = wc.conflict
	if id, ok := wc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := wc.mutation.CreatedAt(); ok {
		_spec.SetField(whatsapp.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := wc.mutation.UpdatedAt(); ok {
		_spec.SetField(whatsapp.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := wc.mutation.Status(); ok {
		_spec.SetField(whatsapp.FieldStatus, field.TypeUint8, value)
		_node.Status = value
	}
	if value, ok := wc.mutation.DeletedAt(); ok {
		_spec.SetField(whatsapp.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := wc.mutation.WaID(); ok {
		_spec.SetField(whatsapp.FieldWaID, field.TypeString, value)
		_node.WaID = value
	}
	if value, ok := wc.mutation.WaName(); ok {
		_spec.SetField(whatsapp.FieldWaName, field.TypeString, value)
		_node.WaName = value
	}
	if value, ok := wc.mutation.Callback(); ok {
		_spec.SetField(whatsapp.FieldCallback, field.TypeString, value)
		_node.Callback = value
	}
	if value, ok := wc.mutation.Account(); ok {
		_spec.SetField(whatsapp.FieldAccount, field.TypeString, value)
		_node.Account = value
	}
	if value, ok := wc.mutation.Cc(); ok {
		_spec.SetField(whatsapp.FieldCc, field.TypeString, value)
		_node.Cc = value
	}
	if value, ok := wc.mutation.Phone(); ok {
		_spec.SetField(whatsapp.FieldPhone, field.TypeString, value)
		_node.Phone = value
	}
	if value, ok := wc.mutation.CcPhone(); ok {
		_spec.SetField(whatsapp.FieldCcPhone, field.TypeString, value)
		_node.CcPhone = value
	}
	if value, ok := wc.mutation.PhoneName(); ok {
		_spec.SetField(whatsapp.FieldPhoneName, field.TypeString, value)
		_node.PhoneName = value
	}
	if value, ok := wc.mutation.PhoneStatus(); ok {
		_spec.SetField(whatsapp.FieldPhoneStatus, field.TypeInt8, value)
		_node.PhoneStatus = value
	}
	if value, ok := wc.mutation.OrganizationID(); ok {
		_spec.SetField(whatsapp.FieldOrganizationID, field.TypeUint64, value)
		_node.OrganizationID = value
	}
	if value, ok := wc.mutation.APIBase(); ok {
		_spec.SetField(whatsapp.FieldAPIBase, field.TypeString, value)
		_node.APIBase = value
	}
	if value, ok := wc.mutation.APIKey(); ok {
		_spec.SetField(whatsapp.FieldAPIKey, field.TypeString, value)
		_node.APIKey = value
	}
	if value, ok := wc.mutation.AllowList(); ok {
		_spec.SetField(whatsapp.FieldAllowList, field.TypeJSON, value)
		_node.AllowList = value
	}
	if value, ok := wc.mutation.GroupAllowList(); ok {
		_spec.SetField(whatsapp.FieldGroupAllowList, field.TypeJSON, value)
		_node.GroupAllowList = value
	}
	if value, ok := wc.mutation.BlockList(); ok {
		_spec.SetField(whatsapp.FieldBlockList, field.TypeJSON, value)
		_node.BlockList = value
	}
	if value, ok := wc.mutation.GroupBlockList(); ok {
		_spec.SetField(whatsapp.FieldGroupBlockList, field.TypeJSON, value)
		_node.GroupBlockList = value
	}
	if nodes := wc.mutation.AgentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   whatsapp.AgentTable,
			Columns: []string{whatsapp.AgentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.AgentID = nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

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

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

type (
	// WhatsappUpsertOne is the builder for "upsert"-ing
	//  one Whatsapp node.
	WhatsappUpsertOne struct {
		create *WhatsappCreate
	}

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

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

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

// SetStatus sets the "status" field.
func (u *WhatsappUpsert) SetStatus(v uint8) *WhatsappUpsert {
	u.Set(whatsapp.FieldStatus, v)
	return u
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateStatus() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldStatus)
	return u
}

// AddStatus adds v to the "status" field.
func (u *WhatsappUpsert) AddStatus(v uint8) *WhatsappUpsert {
	u.Add(whatsapp.FieldStatus, v)
	return u
}

// ClearStatus clears the value of the "status" field.
func (u *WhatsappUpsert) ClearStatus() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldStatus)
	return u
}

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

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

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

// SetWaID sets the "wa_id" field.
func (u *WhatsappUpsert) SetWaID(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldWaID, v)
	return u
}

// UpdateWaID sets the "wa_id" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateWaID() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldWaID)
	return u
}

// ClearWaID clears the value of the "wa_id" field.
func (u *WhatsappUpsert) ClearWaID() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldWaID)
	return u
}

// SetWaName sets the "wa_name" field.
func (u *WhatsappUpsert) SetWaName(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldWaName, v)
	return u
}

// UpdateWaName sets the "wa_name" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateWaName() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldWaName)
	return u
}

// ClearWaName clears the value of the "wa_name" field.
func (u *WhatsappUpsert) ClearWaName() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldWaName)
	return u
}

// SetCallback sets the "callback" field.
func (u *WhatsappUpsert) SetCallback(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldCallback, v)
	return u
}

// UpdateCallback sets the "callback" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateCallback() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldCallback)
	return u
}

// ClearCallback clears the value of the "callback" field.
func (u *WhatsappUpsert) ClearCallback() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldCallback)
	return u
}

// SetAgentID sets the "agent_id" field.
func (u *WhatsappUpsert) SetAgentID(v uint64) *WhatsappUpsert {
	u.Set(whatsapp.FieldAgentID, v)
	return u
}

// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateAgentID() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldAgentID)
	return u
}

// SetAccount sets the "account" field.
func (u *WhatsappUpsert) SetAccount(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldAccount, v)
	return u
}

// UpdateAccount sets the "account" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateAccount() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldAccount)
	return u
}

// ClearAccount clears the value of the "account" field.
func (u *WhatsappUpsert) ClearAccount() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldAccount)
	return u
}

// SetCc sets the "cc" field.
func (u *WhatsappUpsert) SetCc(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldCc, v)
	return u
}

// UpdateCc sets the "cc" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateCc() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldCc)
	return u
}

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

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

// SetCcPhone sets the "cc_phone" field.
func (u *WhatsappUpsert) SetCcPhone(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldCcPhone, v)
	return u
}

// UpdateCcPhone sets the "cc_phone" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateCcPhone() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldCcPhone)
	return u
}

// SetPhoneName sets the "phone_name" field.
func (u *WhatsappUpsert) SetPhoneName(v string) *WhatsappUpsert {
	u.Set(whatsapp.FieldPhoneName, v)
	return u
}

// UpdatePhoneName sets the "phone_name" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdatePhoneName() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldPhoneName)
	return u
}

// SetPhoneStatus sets the "phone_status" field.
func (u *WhatsappUpsert) SetPhoneStatus(v int8) *WhatsappUpsert {
	u.Set(whatsapp.FieldPhoneStatus, v)
	return u
}

// UpdatePhoneStatus sets the "phone_status" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdatePhoneStatus() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldPhoneStatus)
	return u
}

// AddPhoneStatus adds v to the "phone_status" field.
func (u *WhatsappUpsert) AddPhoneStatus(v int8) *WhatsappUpsert {
	u.Add(whatsapp.FieldPhoneStatus, v)
	return u
}

// SetOrganizationID sets the "organization_id" field.
func (u *WhatsappUpsert) SetOrganizationID(v uint64) *WhatsappUpsert {
	u.Set(whatsapp.FieldOrganizationID, v)
	return u
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateOrganizationID() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldOrganizationID)
	return u
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *WhatsappUpsert) AddOrganizationID(v uint64) *WhatsappUpsert {
	u.Add(whatsapp.FieldOrganizationID, v)
	return u
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *WhatsappUpsert) ClearOrganizationID() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldOrganizationID)
	return u
}

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

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

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

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

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

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

// SetAllowList sets the "allow_list" field.
func (u *WhatsappUpsert) SetAllowList(v []string) *WhatsappUpsert {
	u.Set(whatsapp.FieldAllowList, v)
	return u
}

// UpdateAllowList sets the "allow_list" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateAllowList() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldAllowList)
	return u
}

// ClearAllowList clears the value of the "allow_list" field.
func (u *WhatsappUpsert) ClearAllowList() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldAllowList)
	return u
}

// SetGroupAllowList sets the "group_allow_list" field.
func (u *WhatsappUpsert) SetGroupAllowList(v []string) *WhatsappUpsert {
	u.Set(whatsapp.FieldGroupAllowList, v)
	return u
}

// UpdateGroupAllowList sets the "group_allow_list" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateGroupAllowList() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldGroupAllowList)
	return u
}

// ClearGroupAllowList clears the value of the "group_allow_list" field.
func (u *WhatsappUpsert) ClearGroupAllowList() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldGroupAllowList)
	return u
}

// SetBlockList sets the "block_list" field.
func (u *WhatsappUpsert) SetBlockList(v []string) *WhatsappUpsert {
	u.Set(whatsapp.FieldBlockList, v)
	return u
}

// UpdateBlockList sets the "block_list" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateBlockList() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldBlockList)
	return u
}

// ClearBlockList clears the value of the "block_list" field.
func (u *WhatsappUpsert) ClearBlockList() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldBlockList)
	return u
}

// SetGroupBlockList sets the "group_block_list" field.
func (u *WhatsappUpsert) SetGroupBlockList(v []string) *WhatsappUpsert {
	u.Set(whatsapp.FieldGroupBlockList, v)
	return u
}

// UpdateGroupBlockList sets the "group_block_list" field to the value that was provided on create.
func (u *WhatsappUpsert) UpdateGroupBlockList() *WhatsappUpsert {
	u.SetExcluded(whatsapp.FieldGroupBlockList)
	return u
}

// ClearGroupBlockList clears the value of the "group_block_list" field.
func (u *WhatsappUpsert) ClearGroupBlockList() *WhatsappUpsert {
	u.SetNull(whatsapp.FieldGroupBlockList)
	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.Whatsapp.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(whatsapp.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WhatsappUpsertOne) UpdateNewValues() *WhatsappUpsertOne {
	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(whatsapp.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(whatsapp.FieldCreatedAt)
		}
	}))
	return u
}

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

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

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

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

// SetStatus sets the "status" field.
func (u *WhatsappUpsertOne) SetStatus(v uint8) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *WhatsappUpsertOne) AddStatus(v uint8) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.AddStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateStatus() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateStatus()
	})
}

// ClearStatus clears the value of the "status" field.
func (u *WhatsappUpsertOne) ClearStatus() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearStatus()
	})
}

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

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

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

// SetWaID sets the "wa_id" field.
func (u *WhatsappUpsertOne) SetWaID(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetWaID(v)
	})
}

// UpdateWaID sets the "wa_id" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateWaID() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateWaID()
	})
}

// ClearWaID clears the value of the "wa_id" field.
func (u *WhatsappUpsertOne) ClearWaID() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearWaID()
	})
}

// SetWaName sets the "wa_name" field.
func (u *WhatsappUpsertOne) SetWaName(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetWaName(v)
	})
}

// UpdateWaName sets the "wa_name" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateWaName() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateWaName()
	})
}

// ClearWaName clears the value of the "wa_name" field.
func (u *WhatsappUpsertOne) ClearWaName() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearWaName()
	})
}

// SetCallback sets the "callback" field.
func (u *WhatsappUpsertOne) SetCallback(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetCallback(v)
	})
}

// UpdateCallback sets the "callback" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateCallback() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateCallback()
	})
}

// ClearCallback clears the value of the "callback" field.
func (u *WhatsappUpsertOne) ClearCallback() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearCallback()
	})
}

// SetAgentID sets the "agent_id" field.
func (u *WhatsappUpsertOne) SetAgentID(v uint64) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetAgentID(v)
	})
}

// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateAgentID() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateAgentID()
	})
}

// SetAccount sets the "account" field.
func (u *WhatsappUpsertOne) SetAccount(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetAccount(v)
	})
}

// UpdateAccount sets the "account" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateAccount() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateAccount()
	})
}

// ClearAccount clears the value of the "account" field.
func (u *WhatsappUpsertOne) ClearAccount() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearAccount()
	})
}

// SetCc sets the "cc" field.
func (u *WhatsappUpsertOne) SetCc(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetCc(v)
	})
}

// UpdateCc sets the "cc" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateCc() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateCc()
	})
}

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

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

// SetCcPhone sets the "cc_phone" field.
func (u *WhatsappUpsertOne) SetCcPhone(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetCcPhone(v)
	})
}

// UpdateCcPhone sets the "cc_phone" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateCcPhone() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateCcPhone()
	})
}

// SetPhoneName sets the "phone_name" field.
func (u *WhatsappUpsertOne) SetPhoneName(v string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetPhoneName(v)
	})
}

// UpdatePhoneName sets the "phone_name" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdatePhoneName() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdatePhoneName()
	})
}

// SetPhoneStatus sets the "phone_status" field.
func (u *WhatsappUpsertOne) SetPhoneStatus(v int8) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetPhoneStatus(v)
	})
}

// AddPhoneStatus adds v to the "phone_status" field.
func (u *WhatsappUpsertOne) AddPhoneStatus(v int8) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.AddPhoneStatus(v)
	})
}

// UpdatePhoneStatus sets the "phone_status" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdatePhoneStatus() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdatePhoneStatus()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *WhatsappUpsertOne) SetOrganizationID(v uint64) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *WhatsappUpsertOne) AddOrganizationID(v uint64) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateOrganizationID() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *WhatsappUpsertOne) ClearOrganizationID() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearOrganizationID()
	})
}

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

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

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

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

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

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

// SetAllowList sets the "allow_list" field.
func (u *WhatsappUpsertOne) SetAllowList(v []string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetAllowList(v)
	})
}

// UpdateAllowList sets the "allow_list" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateAllowList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateAllowList()
	})
}

// ClearAllowList clears the value of the "allow_list" field.
func (u *WhatsappUpsertOne) ClearAllowList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearAllowList()
	})
}

// SetGroupAllowList sets the "group_allow_list" field.
func (u *WhatsappUpsertOne) SetGroupAllowList(v []string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetGroupAllowList(v)
	})
}

// UpdateGroupAllowList sets the "group_allow_list" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateGroupAllowList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateGroupAllowList()
	})
}

// ClearGroupAllowList clears the value of the "group_allow_list" field.
func (u *WhatsappUpsertOne) ClearGroupAllowList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearGroupAllowList()
	})
}

// SetBlockList sets the "block_list" field.
func (u *WhatsappUpsertOne) SetBlockList(v []string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetBlockList(v)
	})
}

// UpdateBlockList sets the "block_list" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateBlockList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateBlockList()
	})
}

// ClearBlockList clears the value of the "block_list" field.
func (u *WhatsappUpsertOne) ClearBlockList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearBlockList()
	})
}

// SetGroupBlockList sets the "group_block_list" field.
func (u *WhatsappUpsertOne) SetGroupBlockList(v []string) *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetGroupBlockList(v)
	})
}

// UpdateGroupBlockList sets the "group_block_list" field to the value that was provided on create.
func (u *WhatsappUpsertOne) UpdateGroupBlockList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateGroupBlockList()
	})
}

// ClearGroupBlockList clears the value of the "group_block_list" field.
func (u *WhatsappUpsertOne) ClearGroupBlockList() *WhatsappUpsertOne {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearGroupBlockList()
	})
}

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

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

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

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

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

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

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

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

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

// WhatsappUpsertBulk is the builder for "upsert"-ing
// a bulk of Whatsapp nodes.
type WhatsappUpsertBulk struct {
	create *WhatsappCreateBulk
}

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

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

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

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

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

// SetStatus sets the "status" field.
func (u *WhatsappUpsertBulk) SetStatus(v uint8) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *WhatsappUpsertBulk) AddStatus(v uint8) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.AddStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateStatus() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateStatus()
	})
}

// ClearStatus clears the value of the "status" field.
func (u *WhatsappUpsertBulk) ClearStatus() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearStatus()
	})
}

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

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

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

// SetWaID sets the "wa_id" field.
func (u *WhatsappUpsertBulk) SetWaID(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetWaID(v)
	})
}

// UpdateWaID sets the "wa_id" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateWaID() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateWaID()
	})
}

// ClearWaID clears the value of the "wa_id" field.
func (u *WhatsappUpsertBulk) ClearWaID() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearWaID()
	})
}

// SetWaName sets the "wa_name" field.
func (u *WhatsappUpsertBulk) SetWaName(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetWaName(v)
	})
}

// UpdateWaName sets the "wa_name" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateWaName() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateWaName()
	})
}

// ClearWaName clears the value of the "wa_name" field.
func (u *WhatsappUpsertBulk) ClearWaName() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearWaName()
	})
}

// SetCallback sets the "callback" field.
func (u *WhatsappUpsertBulk) SetCallback(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetCallback(v)
	})
}

// UpdateCallback sets the "callback" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateCallback() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateCallback()
	})
}

// ClearCallback clears the value of the "callback" field.
func (u *WhatsappUpsertBulk) ClearCallback() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearCallback()
	})
}

// SetAgentID sets the "agent_id" field.
func (u *WhatsappUpsertBulk) SetAgentID(v uint64) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetAgentID(v)
	})
}

// UpdateAgentID sets the "agent_id" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateAgentID() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateAgentID()
	})
}

// SetAccount sets the "account" field.
func (u *WhatsappUpsertBulk) SetAccount(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetAccount(v)
	})
}

// UpdateAccount sets the "account" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateAccount() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateAccount()
	})
}

// ClearAccount clears the value of the "account" field.
func (u *WhatsappUpsertBulk) ClearAccount() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearAccount()
	})
}

// SetCc sets the "cc" field.
func (u *WhatsappUpsertBulk) SetCc(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetCc(v)
	})
}

// UpdateCc sets the "cc" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateCc() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateCc()
	})
}

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

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

// SetCcPhone sets the "cc_phone" field.
func (u *WhatsappUpsertBulk) SetCcPhone(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetCcPhone(v)
	})
}

// UpdateCcPhone sets the "cc_phone" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateCcPhone() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateCcPhone()
	})
}

// SetPhoneName sets the "phone_name" field.
func (u *WhatsappUpsertBulk) SetPhoneName(v string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetPhoneName(v)
	})
}

// UpdatePhoneName sets the "phone_name" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdatePhoneName() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdatePhoneName()
	})
}

// SetPhoneStatus sets the "phone_status" field.
func (u *WhatsappUpsertBulk) SetPhoneStatus(v int8) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetPhoneStatus(v)
	})
}

// AddPhoneStatus adds v to the "phone_status" field.
func (u *WhatsappUpsertBulk) AddPhoneStatus(v int8) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.AddPhoneStatus(v)
	})
}

// UpdatePhoneStatus sets the "phone_status" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdatePhoneStatus() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdatePhoneStatus()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *WhatsappUpsertBulk) SetOrganizationID(v uint64) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *WhatsappUpsertBulk) AddOrganizationID(v uint64) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateOrganizationID() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *WhatsappUpsertBulk) ClearOrganizationID() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearOrganizationID()
	})
}

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

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

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

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

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

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

// SetAllowList sets the "allow_list" field.
func (u *WhatsappUpsertBulk) SetAllowList(v []string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetAllowList(v)
	})
}

// UpdateAllowList sets the "allow_list" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateAllowList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateAllowList()
	})
}

// ClearAllowList clears the value of the "allow_list" field.
func (u *WhatsappUpsertBulk) ClearAllowList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearAllowList()
	})
}

// SetGroupAllowList sets the "group_allow_list" field.
func (u *WhatsappUpsertBulk) SetGroupAllowList(v []string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetGroupAllowList(v)
	})
}

// UpdateGroupAllowList sets the "group_allow_list" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateGroupAllowList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateGroupAllowList()
	})
}

// ClearGroupAllowList clears the value of the "group_allow_list" field.
func (u *WhatsappUpsertBulk) ClearGroupAllowList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearGroupAllowList()
	})
}

// SetBlockList sets the "block_list" field.
func (u *WhatsappUpsertBulk) SetBlockList(v []string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetBlockList(v)
	})
}

// UpdateBlockList sets the "block_list" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateBlockList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateBlockList()
	})
}

// ClearBlockList clears the value of the "block_list" field.
func (u *WhatsappUpsertBulk) ClearBlockList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearBlockList()
	})
}

// SetGroupBlockList sets the "group_block_list" field.
func (u *WhatsappUpsertBulk) SetGroupBlockList(v []string) *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.SetGroupBlockList(v)
	})
}

// UpdateGroupBlockList sets the "group_block_list" field to the value that was provided on create.
func (u *WhatsappUpsertBulk) UpdateGroupBlockList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.UpdateGroupBlockList()
	})
}

// ClearGroupBlockList clears the value of the "group_block_list" field.
func (u *WhatsappUpsertBulk) ClearGroupBlockList() *WhatsappUpsertBulk {
	return u.Update(func(s *WhatsappUpsert) {
		s.ClearGroupBlockList()
	})
}

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

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