// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/buildbarn/bb-portal/ent/gen/ent/networkmetrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
	"github.com/buildbarn/bb-portal/ent/gen/ent/systemnetworkstats"
)

// SystemNetworkStatsUpdate is the builder for updating SystemNetworkStats entities.
type SystemNetworkStatsUpdate struct {
	config
	hooks    []Hook
	mutation *SystemNetworkStatsMutation
}

// Where appends a list predicates to the SystemNetworkStatsUpdate builder.
func (snsu *SystemNetworkStatsUpdate) Where(ps ...predicate.SystemNetworkStats) *SystemNetworkStatsUpdate {
	snsu.mutation.Where(ps...)
	return snsu
}

// SetBytesSent sets the "bytes_sent" field.
func (snsu *SystemNetworkStatsUpdate) SetBytesSent(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetBytesSent()
	snsu.mutation.SetBytesSent(u)
	return snsu
}

// SetNillableBytesSent sets the "bytes_sent" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillableBytesSent(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetBytesSent(*u)
	}
	return snsu
}

// AddBytesSent adds u to the "bytes_sent" field.
func (snsu *SystemNetworkStatsUpdate) AddBytesSent(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddBytesSent(u)
	return snsu
}

// ClearBytesSent clears the value of the "bytes_sent" field.
func (snsu *SystemNetworkStatsUpdate) ClearBytesSent() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearBytesSent()
	return snsu
}

// SetBytesRecv sets the "bytes_recv" field.
func (snsu *SystemNetworkStatsUpdate) SetBytesRecv(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetBytesRecv()
	snsu.mutation.SetBytesRecv(u)
	return snsu
}

// SetNillableBytesRecv sets the "bytes_recv" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillableBytesRecv(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetBytesRecv(*u)
	}
	return snsu
}

// AddBytesRecv adds u to the "bytes_recv" field.
func (snsu *SystemNetworkStatsUpdate) AddBytesRecv(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddBytesRecv(u)
	return snsu
}

// ClearBytesRecv clears the value of the "bytes_recv" field.
func (snsu *SystemNetworkStatsUpdate) ClearBytesRecv() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearBytesRecv()
	return snsu
}

// SetPacketsSent sets the "packets_sent" field.
func (snsu *SystemNetworkStatsUpdate) SetPacketsSent(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetPacketsSent()
	snsu.mutation.SetPacketsSent(u)
	return snsu
}

// SetNillablePacketsSent sets the "packets_sent" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillablePacketsSent(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetPacketsSent(*u)
	}
	return snsu
}

// AddPacketsSent adds u to the "packets_sent" field.
func (snsu *SystemNetworkStatsUpdate) AddPacketsSent(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddPacketsSent(u)
	return snsu
}

// ClearPacketsSent clears the value of the "packets_sent" field.
func (snsu *SystemNetworkStatsUpdate) ClearPacketsSent() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearPacketsSent()
	return snsu
}

// SetPacketsRecv sets the "packets_recv" field.
func (snsu *SystemNetworkStatsUpdate) SetPacketsRecv(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetPacketsRecv()
	snsu.mutation.SetPacketsRecv(u)
	return snsu
}

// SetNillablePacketsRecv sets the "packets_recv" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillablePacketsRecv(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetPacketsRecv(*u)
	}
	return snsu
}

// AddPacketsRecv adds u to the "packets_recv" field.
func (snsu *SystemNetworkStatsUpdate) AddPacketsRecv(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddPacketsRecv(u)
	return snsu
}

// ClearPacketsRecv clears the value of the "packets_recv" field.
func (snsu *SystemNetworkStatsUpdate) ClearPacketsRecv() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearPacketsRecv()
	return snsu
}

// SetPeakBytesSentPerSec sets the "peak_bytes_sent_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) SetPeakBytesSentPerSec(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetPeakBytesSentPerSec()
	snsu.mutation.SetPeakBytesSentPerSec(u)
	return snsu
}

// SetNillablePeakBytesSentPerSec sets the "peak_bytes_sent_per_sec" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillablePeakBytesSentPerSec(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetPeakBytesSentPerSec(*u)
	}
	return snsu
}

// AddPeakBytesSentPerSec adds u to the "peak_bytes_sent_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) AddPeakBytesSentPerSec(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddPeakBytesSentPerSec(u)
	return snsu
}

// ClearPeakBytesSentPerSec clears the value of the "peak_bytes_sent_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) ClearPeakBytesSentPerSec() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearPeakBytesSentPerSec()
	return snsu
}

// SetPeakBytesRecvPerSec sets the "peak_bytes_recv_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) SetPeakBytesRecvPerSec(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetPeakBytesRecvPerSec()
	snsu.mutation.SetPeakBytesRecvPerSec(u)
	return snsu
}

// SetNillablePeakBytesRecvPerSec sets the "peak_bytes_recv_per_sec" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillablePeakBytesRecvPerSec(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetPeakBytesRecvPerSec(*u)
	}
	return snsu
}

// AddPeakBytesRecvPerSec adds u to the "peak_bytes_recv_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) AddPeakBytesRecvPerSec(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddPeakBytesRecvPerSec(u)
	return snsu
}

// ClearPeakBytesRecvPerSec clears the value of the "peak_bytes_recv_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) ClearPeakBytesRecvPerSec() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearPeakBytesRecvPerSec()
	return snsu
}

// SetPeakPacketsSentPerSec sets the "peak_packets_sent_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) SetPeakPacketsSentPerSec(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetPeakPacketsSentPerSec()
	snsu.mutation.SetPeakPacketsSentPerSec(u)
	return snsu
}

// SetNillablePeakPacketsSentPerSec sets the "peak_packets_sent_per_sec" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillablePeakPacketsSentPerSec(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetPeakPacketsSentPerSec(*u)
	}
	return snsu
}

// AddPeakPacketsSentPerSec adds u to the "peak_packets_sent_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) AddPeakPacketsSentPerSec(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddPeakPacketsSentPerSec(u)
	return snsu
}

// ClearPeakPacketsSentPerSec clears the value of the "peak_packets_sent_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) ClearPeakPacketsSentPerSec() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearPeakPacketsSentPerSec()
	return snsu
}

// SetPeakPacketsRecvPerSec sets the "peak_packets_recv_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) SetPeakPacketsRecvPerSec(u uint64) *SystemNetworkStatsUpdate {
	snsu.mutation.ResetPeakPacketsRecvPerSec()
	snsu.mutation.SetPeakPacketsRecvPerSec(u)
	return snsu
}

// SetNillablePeakPacketsRecvPerSec sets the "peak_packets_recv_per_sec" field if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillablePeakPacketsRecvPerSec(u *uint64) *SystemNetworkStatsUpdate {
	if u != nil {
		snsu.SetPeakPacketsRecvPerSec(*u)
	}
	return snsu
}

// AddPeakPacketsRecvPerSec adds u to the "peak_packets_recv_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) AddPeakPacketsRecvPerSec(u int64) *SystemNetworkStatsUpdate {
	snsu.mutation.AddPeakPacketsRecvPerSec(u)
	return snsu
}

// ClearPeakPacketsRecvPerSec clears the value of the "peak_packets_recv_per_sec" field.
func (snsu *SystemNetworkStatsUpdate) ClearPeakPacketsRecvPerSec() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearPeakPacketsRecvPerSec()
	return snsu
}

// SetNetworkMetricsID sets the "network_metrics" edge to the NetworkMetrics entity by ID.
func (snsu *SystemNetworkStatsUpdate) SetNetworkMetricsID(id int) *SystemNetworkStatsUpdate {
	snsu.mutation.SetNetworkMetricsID(id)
	return snsu
}

// SetNillableNetworkMetricsID sets the "network_metrics" edge to the NetworkMetrics entity by ID if the given value is not nil.
func (snsu *SystemNetworkStatsUpdate) SetNillableNetworkMetricsID(id *int) *SystemNetworkStatsUpdate {
	if id != nil {
		snsu = snsu.SetNetworkMetricsID(*id)
	}
	return snsu
}

// SetNetworkMetrics sets the "network_metrics" edge to the NetworkMetrics entity.
func (snsu *SystemNetworkStatsUpdate) SetNetworkMetrics(n *NetworkMetrics) *SystemNetworkStatsUpdate {
	return snsu.SetNetworkMetricsID(n.ID)
}

// Mutation returns the SystemNetworkStatsMutation object of the builder.
func (snsu *SystemNetworkStatsUpdate) Mutation() *SystemNetworkStatsMutation {
	return snsu.mutation
}

// ClearNetworkMetrics clears the "network_metrics" edge to the NetworkMetrics entity.
func (snsu *SystemNetworkStatsUpdate) ClearNetworkMetrics() *SystemNetworkStatsUpdate {
	snsu.mutation.ClearNetworkMetrics()
	return snsu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (snsu *SystemNetworkStatsUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, snsu.sqlSave, snsu.mutation, snsu.hooks)
}

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

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

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

func (snsu *SystemNetworkStatsUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(systemnetworkstats.Table, systemnetworkstats.Columns, sqlgraph.NewFieldSpec(systemnetworkstats.FieldID, field.TypeInt))
	if ps := snsu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := snsu.mutation.BytesSent(); ok {
		_spec.SetField(systemnetworkstats.FieldBytesSent, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedBytesSent(); ok {
		_spec.AddField(systemnetworkstats.FieldBytesSent, field.TypeUint64, value)
	}
	if snsu.mutation.BytesSentCleared() {
		_spec.ClearField(systemnetworkstats.FieldBytesSent, field.TypeUint64)
	}
	if value, ok := snsu.mutation.BytesRecv(); ok {
		_spec.SetField(systemnetworkstats.FieldBytesRecv, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedBytesRecv(); ok {
		_spec.AddField(systemnetworkstats.FieldBytesRecv, field.TypeUint64, value)
	}
	if snsu.mutation.BytesRecvCleared() {
		_spec.ClearField(systemnetworkstats.FieldBytesRecv, field.TypeUint64)
	}
	if value, ok := snsu.mutation.PacketsSent(); ok {
		_spec.SetField(systemnetworkstats.FieldPacketsSent, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedPacketsSent(); ok {
		_spec.AddField(systemnetworkstats.FieldPacketsSent, field.TypeUint64, value)
	}
	if snsu.mutation.PacketsSentCleared() {
		_spec.ClearField(systemnetworkstats.FieldPacketsSent, field.TypeUint64)
	}
	if value, ok := snsu.mutation.PacketsRecv(); ok {
		_spec.SetField(systemnetworkstats.FieldPacketsRecv, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedPacketsRecv(); ok {
		_spec.AddField(systemnetworkstats.FieldPacketsRecv, field.TypeUint64, value)
	}
	if snsu.mutation.PacketsRecvCleared() {
		_spec.ClearField(systemnetworkstats.FieldPacketsRecv, field.TypeUint64)
	}
	if value, ok := snsu.mutation.PeakBytesSentPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakBytesSentPerSec, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedPeakBytesSentPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakBytesSentPerSec, field.TypeUint64, value)
	}
	if snsu.mutation.PeakBytesSentPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakBytesSentPerSec, field.TypeUint64)
	}
	if value, ok := snsu.mutation.PeakBytesRecvPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakBytesRecvPerSec, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedPeakBytesRecvPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakBytesRecvPerSec, field.TypeUint64, value)
	}
	if snsu.mutation.PeakBytesRecvPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakBytesRecvPerSec, field.TypeUint64)
	}
	if value, ok := snsu.mutation.PeakPacketsSentPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakPacketsSentPerSec, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedPeakPacketsSentPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakPacketsSentPerSec, field.TypeUint64, value)
	}
	if snsu.mutation.PeakPacketsSentPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakPacketsSentPerSec, field.TypeUint64)
	}
	if value, ok := snsu.mutation.PeakPacketsRecvPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakPacketsRecvPerSec, field.TypeUint64, value)
	}
	if value, ok := snsu.mutation.AddedPeakPacketsRecvPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakPacketsRecvPerSec, field.TypeUint64, value)
	}
	if snsu.mutation.PeakPacketsRecvPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakPacketsRecvPerSec, field.TypeUint64)
	}
	if snsu.mutation.NetworkMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   systemnetworkstats.NetworkMetricsTable,
			Columns: []string{systemnetworkstats.NetworkMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(networkmetrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := snsu.mutation.NetworkMetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   systemnetworkstats.NetworkMetricsTable,
			Columns: []string{systemnetworkstats.NetworkMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(networkmetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, snsu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{systemnetworkstats.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	snsu.mutation.done = true
	return n, nil
}

// SystemNetworkStatsUpdateOne is the builder for updating a single SystemNetworkStats entity.
type SystemNetworkStatsUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *SystemNetworkStatsMutation
}

// SetBytesSent sets the "bytes_sent" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetBytesSent(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetBytesSent()
	snsuo.mutation.SetBytesSent(u)
	return snsuo
}

// SetNillableBytesSent sets the "bytes_sent" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillableBytesSent(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetBytesSent(*u)
	}
	return snsuo
}

// AddBytesSent adds u to the "bytes_sent" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddBytesSent(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddBytesSent(u)
	return snsuo
}

// ClearBytesSent clears the value of the "bytes_sent" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearBytesSent() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearBytesSent()
	return snsuo
}

// SetBytesRecv sets the "bytes_recv" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetBytesRecv(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetBytesRecv()
	snsuo.mutation.SetBytesRecv(u)
	return snsuo
}

// SetNillableBytesRecv sets the "bytes_recv" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillableBytesRecv(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetBytesRecv(*u)
	}
	return snsuo
}

// AddBytesRecv adds u to the "bytes_recv" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddBytesRecv(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddBytesRecv(u)
	return snsuo
}

// ClearBytesRecv clears the value of the "bytes_recv" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearBytesRecv() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearBytesRecv()
	return snsuo
}

// SetPacketsSent sets the "packets_sent" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetPacketsSent(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetPacketsSent()
	snsuo.mutation.SetPacketsSent(u)
	return snsuo
}

// SetNillablePacketsSent sets the "packets_sent" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillablePacketsSent(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetPacketsSent(*u)
	}
	return snsuo
}

// AddPacketsSent adds u to the "packets_sent" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddPacketsSent(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddPacketsSent(u)
	return snsuo
}

// ClearPacketsSent clears the value of the "packets_sent" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearPacketsSent() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearPacketsSent()
	return snsuo
}

// SetPacketsRecv sets the "packets_recv" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetPacketsRecv(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetPacketsRecv()
	snsuo.mutation.SetPacketsRecv(u)
	return snsuo
}

// SetNillablePacketsRecv sets the "packets_recv" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillablePacketsRecv(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetPacketsRecv(*u)
	}
	return snsuo
}

// AddPacketsRecv adds u to the "packets_recv" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddPacketsRecv(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddPacketsRecv(u)
	return snsuo
}

// ClearPacketsRecv clears the value of the "packets_recv" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearPacketsRecv() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearPacketsRecv()
	return snsuo
}

// SetPeakBytesSentPerSec sets the "peak_bytes_sent_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetPeakBytesSentPerSec(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetPeakBytesSentPerSec()
	snsuo.mutation.SetPeakBytesSentPerSec(u)
	return snsuo
}

// SetNillablePeakBytesSentPerSec sets the "peak_bytes_sent_per_sec" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillablePeakBytesSentPerSec(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetPeakBytesSentPerSec(*u)
	}
	return snsuo
}

// AddPeakBytesSentPerSec adds u to the "peak_bytes_sent_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddPeakBytesSentPerSec(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddPeakBytesSentPerSec(u)
	return snsuo
}

// ClearPeakBytesSentPerSec clears the value of the "peak_bytes_sent_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearPeakBytesSentPerSec() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearPeakBytesSentPerSec()
	return snsuo
}

// SetPeakBytesRecvPerSec sets the "peak_bytes_recv_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetPeakBytesRecvPerSec(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetPeakBytesRecvPerSec()
	snsuo.mutation.SetPeakBytesRecvPerSec(u)
	return snsuo
}

// SetNillablePeakBytesRecvPerSec sets the "peak_bytes_recv_per_sec" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillablePeakBytesRecvPerSec(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetPeakBytesRecvPerSec(*u)
	}
	return snsuo
}

// AddPeakBytesRecvPerSec adds u to the "peak_bytes_recv_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddPeakBytesRecvPerSec(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddPeakBytesRecvPerSec(u)
	return snsuo
}

// ClearPeakBytesRecvPerSec clears the value of the "peak_bytes_recv_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearPeakBytesRecvPerSec() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearPeakBytesRecvPerSec()
	return snsuo
}

// SetPeakPacketsSentPerSec sets the "peak_packets_sent_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetPeakPacketsSentPerSec(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetPeakPacketsSentPerSec()
	snsuo.mutation.SetPeakPacketsSentPerSec(u)
	return snsuo
}

// SetNillablePeakPacketsSentPerSec sets the "peak_packets_sent_per_sec" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillablePeakPacketsSentPerSec(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetPeakPacketsSentPerSec(*u)
	}
	return snsuo
}

// AddPeakPacketsSentPerSec adds u to the "peak_packets_sent_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddPeakPacketsSentPerSec(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddPeakPacketsSentPerSec(u)
	return snsuo
}

// ClearPeakPacketsSentPerSec clears the value of the "peak_packets_sent_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearPeakPacketsSentPerSec() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearPeakPacketsSentPerSec()
	return snsuo
}

// SetPeakPacketsRecvPerSec sets the "peak_packets_recv_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) SetPeakPacketsRecvPerSec(u uint64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ResetPeakPacketsRecvPerSec()
	snsuo.mutation.SetPeakPacketsRecvPerSec(u)
	return snsuo
}

// SetNillablePeakPacketsRecvPerSec sets the "peak_packets_recv_per_sec" field if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillablePeakPacketsRecvPerSec(u *uint64) *SystemNetworkStatsUpdateOne {
	if u != nil {
		snsuo.SetPeakPacketsRecvPerSec(*u)
	}
	return snsuo
}

// AddPeakPacketsRecvPerSec adds u to the "peak_packets_recv_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) AddPeakPacketsRecvPerSec(u int64) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.AddPeakPacketsRecvPerSec(u)
	return snsuo
}

// ClearPeakPacketsRecvPerSec clears the value of the "peak_packets_recv_per_sec" field.
func (snsuo *SystemNetworkStatsUpdateOne) ClearPeakPacketsRecvPerSec() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearPeakPacketsRecvPerSec()
	return snsuo
}

// SetNetworkMetricsID sets the "network_metrics" edge to the NetworkMetrics entity by ID.
func (snsuo *SystemNetworkStatsUpdateOne) SetNetworkMetricsID(id int) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.SetNetworkMetricsID(id)
	return snsuo
}

// SetNillableNetworkMetricsID sets the "network_metrics" edge to the NetworkMetrics entity by ID if the given value is not nil.
func (snsuo *SystemNetworkStatsUpdateOne) SetNillableNetworkMetricsID(id *int) *SystemNetworkStatsUpdateOne {
	if id != nil {
		snsuo = snsuo.SetNetworkMetricsID(*id)
	}
	return snsuo
}

// SetNetworkMetrics sets the "network_metrics" edge to the NetworkMetrics entity.
func (snsuo *SystemNetworkStatsUpdateOne) SetNetworkMetrics(n *NetworkMetrics) *SystemNetworkStatsUpdateOne {
	return snsuo.SetNetworkMetricsID(n.ID)
}

// Mutation returns the SystemNetworkStatsMutation object of the builder.
func (snsuo *SystemNetworkStatsUpdateOne) Mutation() *SystemNetworkStatsMutation {
	return snsuo.mutation
}

// ClearNetworkMetrics clears the "network_metrics" edge to the NetworkMetrics entity.
func (snsuo *SystemNetworkStatsUpdateOne) ClearNetworkMetrics() *SystemNetworkStatsUpdateOne {
	snsuo.mutation.ClearNetworkMetrics()
	return snsuo
}

// Where appends a list predicates to the SystemNetworkStatsUpdate builder.
func (snsuo *SystemNetworkStatsUpdateOne) Where(ps ...predicate.SystemNetworkStats) *SystemNetworkStatsUpdateOne {
	snsuo.mutation.Where(ps...)
	return snsuo
}

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

// Save executes the query and returns the updated SystemNetworkStats entity.
func (snsuo *SystemNetworkStatsUpdateOne) Save(ctx context.Context) (*SystemNetworkStats, error) {
	return withHooks(ctx, snsuo.sqlSave, snsuo.mutation, snsuo.hooks)
}

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

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

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

func (snsuo *SystemNetworkStatsUpdateOne) sqlSave(ctx context.Context) (_node *SystemNetworkStats, err error) {
	_spec := sqlgraph.NewUpdateSpec(systemnetworkstats.Table, systemnetworkstats.Columns, sqlgraph.NewFieldSpec(systemnetworkstats.FieldID, field.TypeInt))
	id, ok := snsuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SystemNetworkStats.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := snsuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, systemnetworkstats.FieldID)
		for _, f := range fields {
			if !systemnetworkstats.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != systemnetworkstats.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := snsuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := snsuo.mutation.BytesSent(); ok {
		_spec.SetField(systemnetworkstats.FieldBytesSent, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedBytesSent(); ok {
		_spec.AddField(systemnetworkstats.FieldBytesSent, field.TypeUint64, value)
	}
	if snsuo.mutation.BytesSentCleared() {
		_spec.ClearField(systemnetworkstats.FieldBytesSent, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.BytesRecv(); ok {
		_spec.SetField(systemnetworkstats.FieldBytesRecv, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedBytesRecv(); ok {
		_spec.AddField(systemnetworkstats.FieldBytesRecv, field.TypeUint64, value)
	}
	if snsuo.mutation.BytesRecvCleared() {
		_spec.ClearField(systemnetworkstats.FieldBytesRecv, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.PacketsSent(); ok {
		_spec.SetField(systemnetworkstats.FieldPacketsSent, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedPacketsSent(); ok {
		_spec.AddField(systemnetworkstats.FieldPacketsSent, field.TypeUint64, value)
	}
	if snsuo.mutation.PacketsSentCleared() {
		_spec.ClearField(systemnetworkstats.FieldPacketsSent, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.PacketsRecv(); ok {
		_spec.SetField(systemnetworkstats.FieldPacketsRecv, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedPacketsRecv(); ok {
		_spec.AddField(systemnetworkstats.FieldPacketsRecv, field.TypeUint64, value)
	}
	if snsuo.mutation.PacketsRecvCleared() {
		_spec.ClearField(systemnetworkstats.FieldPacketsRecv, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.PeakBytesSentPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakBytesSentPerSec, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedPeakBytesSentPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakBytesSentPerSec, field.TypeUint64, value)
	}
	if snsuo.mutation.PeakBytesSentPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakBytesSentPerSec, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.PeakBytesRecvPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakBytesRecvPerSec, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedPeakBytesRecvPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakBytesRecvPerSec, field.TypeUint64, value)
	}
	if snsuo.mutation.PeakBytesRecvPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakBytesRecvPerSec, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.PeakPacketsSentPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakPacketsSentPerSec, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedPeakPacketsSentPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakPacketsSentPerSec, field.TypeUint64, value)
	}
	if snsuo.mutation.PeakPacketsSentPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakPacketsSentPerSec, field.TypeUint64)
	}
	if value, ok := snsuo.mutation.PeakPacketsRecvPerSec(); ok {
		_spec.SetField(systemnetworkstats.FieldPeakPacketsRecvPerSec, field.TypeUint64, value)
	}
	if value, ok := snsuo.mutation.AddedPeakPacketsRecvPerSec(); ok {
		_spec.AddField(systemnetworkstats.FieldPeakPacketsRecvPerSec, field.TypeUint64, value)
	}
	if snsuo.mutation.PeakPacketsRecvPerSecCleared() {
		_spec.ClearField(systemnetworkstats.FieldPeakPacketsRecvPerSec, field.TypeUint64)
	}
	if snsuo.mutation.NetworkMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   systemnetworkstats.NetworkMetricsTable,
			Columns: []string{systemnetworkstats.NetworkMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(networkmetrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := snsuo.mutation.NetworkMetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   systemnetworkstats.NetworkMetricsTable,
			Columns: []string{systemnetworkstats.NetworkMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(networkmetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &SystemNetworkStats{config: snsuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, snsuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{systemnetworkstats.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	snsuo.mutation.done = true
	return _node, nil
}
