// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WhatsappChannelUpdate is the builder for updating WhatsappChannel entities.
type WhatsappChannelUpdate struct {
	config
	hooks    []Hook
	mutation *WhatsappChannelMutation
}

// Where appends a list predicates to the WhatsappChannelUpdate builder.
func (wcu *WhatsappChannelUpdate) Where(ps ...predicate.WhatsappChannel) *WhatsappChannelUpdate {
	wcu.mutation.Where(ps...)
	return wcu
}

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

// SetStatus sets the "status" field.
func (wcu *WhatsappChannelUpdate) SetStatus(u uint8) *WhatsappChannelUpdate {
	wcu.mutation.ResetStatus()
	wcu.mutation.SetStatus(u)
	return wcu
}

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

// AddStatus adds u to the "status" field.
func (wcu *WhatsappChannelUpdate) AddStatus(u int8) *WhatsappChannelUpdate {
	wcu.mutation.AddStatus(u)
	return wcu
}

// ClearStatus clears the value of the "status" field.
func (wcu *WhatsappChannelUpdate) ClearStatus() *WhatsappChannelUpdate {
	wcu.mutation.ClearStatus()
	return wcu
}

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

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

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

// SetAk sets the "ak" field.
func (wcu *WhatsappChannelUpdate) SetAk(s string) *WhatsappChannelUpdate {
	wcu.mutation.SetAk(s)
	return wcu
}

// SetNillableAk sets the "ak" field if the given value is not nil.
func (wcu *WhatsappChannelUpdate) SetNillableAk(s *string) *WhatsappChannelUpdate {
	if s != nil {
		wcu.SetAk(*s)
	}
	return wcu
}

// ClearAk clears the value of the "ak" field.
func (wcu *WhatsappChannelUpdate) ClearAk() *WhatsappChannelUpdate {
	wcu.mutation.ClearAk()
	return wcu
}

// SetSk sets the "sk" field.
func (wcu *WhatsappChannelUpdate) SetSk(s string) *WhatsappChannelUpdate {
	wcu.mutation.SetSk(s)
	return wcu
}

// SetNillableSk sets the "sk" field if the given value is not nil.
func (wcu *WhatsappChannelUpdate) SetNillableSk(s *string) *WhatsappChannelUpdate {
	if s != nil {
		wcu.SetSk(*s)
	}
	return wcu
}

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

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

// ClearWaID clears the value of the "wa_id" field.
func (wcu *WhatsappChannelUpdate) ClearWaID() *WhatsappChannelUpdate {
	wcu.mutation.ClearWaID()
	return wcu
}

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

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

// ClearWaName clears the value of the "wa_name" field.
func (wcu *WhatsappChannelUpdate) ClearWaName() *WhatsappChannelUpdate {
	wcu.mutation.ClearWaName()
	return wcu
}

// SetWabaID sets the "waba_id" field.
func (wcu *WhatsappChannelUpdate) SetWabaID(u uint64) *WhatsappChannelUpdate {
	wcu.mutation.ResetWabaID()
	wcu.mutation.SetWabaID(u)
	return wcu
}

// SetNillableWabaID sets the "waba_id" field if the given value is not nil.
func (wcu *WhatsappChannelUpdate) SetNillableWabaID(u *uint64) *WhatsappChannelUpdate {
	if u != nil {
		wcu.SetWabaID(*u)
	}
	return wcu
}

// AddWabaID adds u to the "waba_id" field.
func (wcu *WhatsappChannelUpdate) AddWabaID(u int64) *WhatsappChannelUpdate {
	wcu.mutation.AddWabaID(u)
	return wcu
}

// SetBusinessID sets the "business_id" field.
func (wcu *WhatsappChannelUpdate) SetBusinessID(u uint64) *WhatsappChannelUpdate {
	wcu.mutation.ResetBusinessID()
	wcu.mutation.SetBusinessID(u)
	return wcu
}

// SetNillableBusinessID sets the "business_id" field if the given value is not nil.
func (wcu *WhatsappChannelUpdate) SetNillableBusinessID(u *uint64) *WhatsappChannelUpdate {
	if u != nil {
		wcu.SetBusinessID(*u)
	}
	return wcu
}

// AddBusinessID adds u to the "business_id" field.
func (wcu *WhatsappChannelUpdate) AddBusinessID(u int64) *WhatsappChannelUpdate {
	wcu.mutation.AddBusinessID(u)
	return wcu
}

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

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

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

// ClearOrganizationID clears the value of the "organization_id" field.
func (wcu *WhatsappChannelUpdate) ClearOrganizationID() *WhatsappChannelUpdate {
	wcu.mutation.ClearOrganizationID()
	return wcu
}

// SetVerifyAccount sets the "verify_account" field.
func (wcu *WhatsappChannelUpdate) SetVerifyAccount(s string) *WhatsappChannelUpdate {
	wcu.mutation.SetVerifyAccount(s)
	return wcu
}

// SetNillableVerifyAccount sets the "verify_account" field if the given value is not nil.
func (wcu *WhatsappChannelUpdate) SetNillableVerifyAccount(s *string) *WhatsappChannelUpdate {
	if s != nil {
		wcu.SetVerifyAccount(*s)
	}
	return wcu
}

// Mutation returns the WhatsappChannelMutation object of the builder.
func (wcu *WhatsappChannelUpdate) Mutation() *WhatsappChannelMutation {
	return wcu.mutation
}

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

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

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

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

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

func (wcu *WhatsappChannelUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(whatsappchannel.Table, whatsappchannel.Columns, sqlgraph.NewFieldSpec(whatsappchannel.FieldID, field.TypeUint64))
	if ps := wcu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wcu.mutation.UpdatedAt(); ok {
		_spec.SetField(whatsappchannel.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := wcu.mutation.Status(); ok {
		_spec.SetField(whatsappchannel.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := wcu.mutation.AddedStatus(); ok {
		_spec.AddField(whatsappchannel.FieldStatus, field.TypeUint8, value)
	}
	if wcu.mutation.StatusCleared() {
		_spec.ClearField(whatsappchannel.FieldStatus, field.TypeUint8)
	}
	if value, ok := wcu.mutation.DeletedAt(); ok {
		_spec.SetField(whatsappchannel.FieldDeletedAt, field.TypeTime, value)
	}
	if wcu.mutation.DeletedAtCleared() {
		_spec.ClearField(whatsappchannel.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := wcu.mutation.Ak(); ok {
		_spec.SetField(whatsappchannel.FieldAk, field.TypeString, value)
	}
	if wcu.mutation.AkCleared() {
		_spec.ClearField(whatsappchannel.FieldAk, field.TypeString)
	}
	if value, ok := wcu.mutation.Sk(); ok {
		_spec.SetField(whatsappchannel.FieldSk, field.TypeString, value)
	}
	if value, ok := wcu.mutation.WaID(); ok {
		_spec.SetField(whatsappchannel.FieldWaID, field.TypeString, value)
	}
	if wcu.mutation.WaIDCleared() {
		_spec.ClearField(whatsappchannel.FieldWaID, field.TypeString)
	}
	if value, ok := wcu.mutation.WaName(); ok {
		_spec.SetField(whatsappchannel.FieldWaName, field.TypeString, value)
	}
	if wcu.mutation.WaNameCleared() {
		_spec.ClearField(whatsappchannel.FieldWaName, field.TypeString)
	}
	if value, ok := wcu.mutation.WabaID(); ok {
		_spec.SetField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
	}
	if value, ok := wcu.mutation.AddedWabaID(); ok {
		_spec.AddField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
	}
	if value, ok := wcu.mutation.BusinessID(); ok {
		_spec.SetField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
	}
	if value, ok := wcu.mutation.AddedBusinessID(); ok {
		_spec.AddField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
	}
	if value, ok := wcu.mutation.OrganizationID(); ok {
		_spec.SetField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := wcu.mutation.AddedOrganizationID(); ok {
		_spec.AddField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
	}
	if wcu.mutation.OrganizationIDCleared() {
		_spec.ClearField(whatsappchannel.FieldOrganizationID, field.TypeUint64)
	}
	if value, ok := wcu.mutation.VerifyAccount(); ok {
		_spec.SetField(whatsappchannel.FieldVerifyAccount, field.TypeString, value)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, wcu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{whatsappchannel.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	wcu.mutation.done = true
	return n, nil
}

// WhatsappChannelUpdateOne is the builder for updating a single WhatsappChannel entity.
type WhatsappChannelUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *WhatsappChannelMutation
}

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

// SetStatus sets the "status" field.
func (wcuo *WhatsappChannelUpdateOne) SetStatus(u uint8) *WhatsappChannelUpdateOne {
	wcuo.mutation.ResetStatus()
	wcuo.mutation.SetStatus(u)
	return wcuo
}

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

// AddStatus adds u to the "status" field.
func (wcuo *WhatsappChannelUpdateOne) AddStatus(u int8) *WhatsappChannelUpdateOne {
	wcuo.mutation.AddStatus(u)
	return wcuo
}

// ClearStatus clears the value of the "status" field.
func (wcuo *WhatsappChannelUpdateOne) ClearStatus() *WhatsappChannelUpdateOne {
	wcuo.mutation.ClearStatus()
	return wcuo
}

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

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

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

// SetAk sets the "ak" field.
func (wcuo *WhatsappChannelUpdateOne) SetAk(s string) *WhatsappChannelUpdateOne {
	wcuo.mutation.SetAk(s)
	return wcuo
}

// SetNillableAk sets the "ak" field if the given value is not nil.
func (wcuo *WhatsappChannelUpdateOne) SetNillableAk(s *string) *WhatsappChannelUpdateOne {
	if s != nil {
		wcuo.SetAk(*s)
	}
	return wcuo
}

// ClearAk clears the value of the "ak" field.
func (wcuo *WhatsappChannelUpdateOne) ClearAk() *WhatsappChannelUpdateOne {
	wcuo.mutation.ClearAk()
	return wcuo
}

// SetSk sets the "sk" field.
func (wcuo *WhatsappChannelUpdateOne) SetSk(s string) *WhatsappChannelUpdateOne {
	wcuo.mutation.SetSk(s)
	return wcuo
}

// SetNillableSk sets the "sk" field if the given value is not nil.
func (wcuo *WhatsappChannelUpdateOne) SetNillableSk(s *string) *WhatsappChannelUpdateOne {
	if s != nil {
		wcuo.SetSk(*s)
	}
	return wcuo
}

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

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

// ClearWaID clears the value of the "wa_id" field.
func (wcuo *WhatsappChannelUpdateOne) ClearWaID() *WhatsappChannelUpdateOne {
	wcuo.mutation.ClearWaID()
	return wcuo
}

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

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

// ClearWaName clears the value of the "wa_name" field.
func (wcuo *WhatsappChannelUpdateOne) ClearWaName() *WhatsappChannelUpdateOne {
	wcuo.mutation.ClearWaName()
	return wcuo
}

// SetWabaID sets the "waba_id" field.
func (wcuo *WhatsappChannelUpdateOne) SetWabaID(u uint64) *WhatsappChannelUpdateOne {
	wcuo.mutation.ResetWabaID()
	wcuo.mutation.SetWabaID(u)
	return wcuo
}

// SetNillableWabaID sets the "waba_id" field if the given value is not nil.
func (wcuo *WhatsappChannelUpdateOne) SetNillableWabaID(u *uint64) *WhatsappChannelUpdateOne {
	if u != nil {
		wcuo.SetWabaID(*u)
	}
	return wcuo
}

// AddWabaID adds u to the "waba_id" field.
func (wcuo *WhatsappChannelUpdateOne) AddWabaID(u int64) *WhatsappChannelUpdateOne {
	wcuo.mutation.AddWabaID(u)
	return wcuo
}

// SetBusinessID sets the "business_id" field.
func (wcuo *WhatsappChannelUpdateOne) SetBusinessID(u uint64) *WhatsappChannelUpdateOne {
	wcuo.mutation.ResetBusinessID()
	wcuo.mutation.SetBusinessID(u)
	return wcuo
}

// SetNillableBusinessID sets the "business_id" field if the given value is not nil.
func (wcuo *WhatsappChannelUpdateOne) SetNillableBusinessID(u *uint64) *WhatsappChannelUpdateOne {
	if u != nil {
		wcuo.SetBusinessID(*u)
	}
	return wcuo
}

// AddBusinessID adds u to the "business_id" field.
func (wcuo *WhatsappChannelUpdateOne) AddBusinessID(u int64) *WhatsappChannelUpdateOne {
	wcuo.mutation.AddBusinessID(u)
	return wcuo
}

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

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

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

// ClearOrganizationID clears the value of the "organization_id" field.
func (wcuo *WhatsappChannelUpdateOne) ClearOrganizationID() *WhatsappChannelUpdateOne {
	wcuo.mutation.ClearOrganizationID()
	return wcuo
}

// SetVerifyAccount sets the "verify_account" field.
func (wcuo *WhatsappChannelUpdateOne) SetVerifyAccount(s string) *WhatsappChannelUpdateOne {
	wcuo.mutation.SetVerifyAccount(s)
	return wcuo
}

// SetNillableVerifyAccount sets the "verify_account" field if the given value is not nil.
func (wcuo *WhatsappChannelUpdateOne) SetNillableVerifyAccount(s *string) *WhatsappChannelUpdateOne {
	if s != nil {
		wcuo.SetVerifyAccount(*s)
	}
	return wcuo
}

// Mutation returns the WhatsappChannelMutation object of the builder.
func (wcuo *WhatsappChannelUpdateOne) Mutation() *WhatsappChannelMutation {
	return wcuo.mutation
}

// Where appends a list predicates to the WhatsappChannelUpdate builder.
func (wcuo *WhatsappChannelUpdateOne) Where(ps ...predicate.WhatsappChannel) *WhatsappChannelUpdateOne {
	wcuo.mutation.Where(ps...)
	return wcuo
}

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

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

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

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

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

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

func (wcuo *WhatsappChannelUpdateOne) sqlSave(ctx context.Context) (_node *WhatsappChannel, err error) {
	_spec := sqlgraph.NewUpdateSpec(whatsappchannel.Table, whatsappchannel.Columns, sqlgraph.NewFieldSpec(whatsappchannel.FieldID, field.TypeUint64))
	id, ok := wcuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WhatsappChannel.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := wcuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, whatsappchannel.FieldID)
		for _, f := range fields {
			if !whatsappchannel.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != whatsappchannel.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := wcuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wcuo.mutation.UpdatedAt(); ok {
		_spec.SetField(whatsappchannel.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := wcuo.mutation.Status(); ok {
		_spec.SetField(whatsappchannel.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := wcuo.mutation.AddedStatus(); ok {
		_spec.AddField(whatsappchannel.FieldStatus, field.TypeUint8, value)
	}
	if wcuo.mutation.StatusCleared() {
		_spec.ClearField(whatsappchannel.FieldStatus, field.TypeUint8)
	}
	if value, ok := wcuo.mutation.DeletedAt(); ok {
		_spec.SetField(whatsappchannel.FieldDeletedAt, field.TypeTime, value)
	}
	if wcuo.mutation.DeletedAtCleared() {
		_spec.ClearField(whatsappchannel.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := wcuo.mutation.Ak(); ok {
		_spec.SetField(whatsappchannel.FieldAk, field.TypeString, value)
	}
	if wcuo.mutation.AkCleared() {
		_spec.ClearField(whatsappchannel.FieldAk, field.TypeString)
	}
	if value, ok := wcuo.mutation.Sk(); ok {
		_spec.SetField(whatsappchannel.FieldSk, field.TypeString, value)
	}
	if value, ok := wcuo.mutation.WaID(); ok {
		_spec.SetField(whatsappchannel.FieldWaID, field.TypeString, value)
	}
	if wcuo.mutation.WaIDCleared() {
		_spec.ClearField(whatsappchannel.FieldWaID, field.TypeString)
	}
	if value, ok := wcuo.mutation.WaName(); ok {
		_spec.SetField(whatsappchannel.FieldWaName, field.TypeString, value)
	}
	if wcuo.mutation.WaNameCleared() {
		_spec.ClearField(whatsappchannel.FieldWaName, field.TypeString)
	}
	if value, ok := wcuo.mutation.WabaID(); ok {
		_spec.SetField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
	}
	if value, ok := wcuo.mutation.AddedWabaID(); ok {
		_spec.AddField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
	}
	if value, ok := wcuo.mutation.BusinessID(); ok {
		_spec.SetField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
	}
	if value, ok := wcuo.mutation.AddedBusinessID(); ok {
		_spec.AddField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
	}
	if value, ok := wcuo.mutation.OrganizationID(); ok {
		_spec.SetField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := wcuo.mutation.AddedOrganizationID(); ok {
		_spec.AddField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
	}
	if wcuo.mutation.OrganizationIDCleared() {
		_spec.ClearField(whatsappchannel.FieldOrganizationID, field.TypeUint64)
	}
	if value, ok := wcuo.mutation.VerifyAccount(); ok {
		_spec.SetField(whatsappchannel.FieldVerifyAccount, field.TypeString, value)
	}
	_node = &WhatsappChannel{config: wcuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, wcuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{whatsappchannel.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	wcuo.mutation.done = true
	return _node, nil
}
