// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/Wei-Shaw/sub2api/ent/channelmonitor"
	"github.com/Wei-Shaw/sub2api/ent/channelmonitordailyrollup"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
)

// ChannelMonitorDailyRollupUpdate is the builder for updating ChannelMonitorDailyRollup entities.
type ChannelMonitorDailyRollupUpdate struct {
	config
	hooks    []Hook
	mutation *ChannelMonitorDailyRollupMutation
}

// Where appends a list predicates to the ChannelMonitorDailyRollupUpdate builder.
func (_u *ChannelMonitorDailyRollupUpdate) Where(ps ...predicate.ChannelMonitorDailyRollup) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetMonitorID sets the "monitor_id" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.SetMonitorID(v)
	return _u
}

// SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableMonitorID(v *int64) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetMonitorID(*v)
	}
	return _u
}

// SetModel sets the "model" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetModel(v string) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.SetModel(v)
	return _u
}

// SetNillableModel sets the "model" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableModel(v *string) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetModel(*v)
	}
	return _u
}

// SetBucketDate sets the "bucket_date" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetBucketDate(v time.Time) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.SetBucketDate(v)
	return _u
}

// SetNillableBucketDate sets the "bucket_date" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableBucketDate(v *time.Time) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetBucketDate(*v)
	}
	return _u
}

// SetTotalChecks sets the "total_checks" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetTotalChecks(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetTotalChecks()
	_u.mutation.SetTotalChecks(v)
	return _u
}

// SetNillableTotalChecks sets the "total_checks" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableTotalChecks(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetTotalChecks(*v)
	}
	return _u
}

// AddTotalChecks adds value to the "total_checks" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddTotalChecks(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddTotalChecks(v)
	return _u
}

// SetOkCount sets the "ok_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetOkCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetOkCount()
	_u.mutation.SetOkCount(v)
	return _u
}

// SetNillableOkCount sets the "ok_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableOkCount(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetOkCount(*v)
	}
	return _u
}

// AddOkCount adds value to the "ok_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddOkCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddOkCount(v)
	return _u
}

// SetOperationalCount sets the "operational_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetOperationalCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetOperationalCount()
	_u.mutation.SetOperationalCount(v)
	return _u
}

// SetNillableOperationalCount sets the "operational_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableOperationalCount(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetOperationalCount(*v)
	}
	return _u
}

// AddOperationalCount adds value to the "operational_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddOperationalCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddOperationalCount(v)
	return _u
}

// SetDegradedCount sets the "degraded_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetDegradedCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetDegradedCount()
	_u.mutation.SetDegradedCount(v)
	return _u
}

// SetNillableDegradedCount sets the "degraded_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableDegradedCount(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetDegradedCount(*v)
	}
	return _u
}

// AddDegradedCount adds value to the "degraded_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddDegradedCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddDegradedCount(v)
	return _u
}

// SetFailedCount sets the "failed_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetFailedCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetFailedCount()
	_u.mutation.SetFailedCount(v)
	return _u
}

// SetNillableFailedCount sets the "failed_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableFailedCount(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetFailedCount(*v)
	}
	return _u
}

// AddFailedCount adds value to the "failed_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddFailedCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddFailedCount(v)
	return _u
}

// SetErrorCount sets the "error_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetErrorCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetErrorCount()
	_u.mutation.SetErrorCount(v)
	return _u
}

// SetNillableErrorCount sets the "error_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableErrorCount(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetErrorCount(*v)
	}
	return _u
}

// AddErrorCount adds value to the "error_count" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddErrorCount(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddErrorCount(v)
	return _u
}

// SetSumLatencyMs sets the "sum_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetSumLatencyMs()
	_u.mutation.SetSumLatencyMs(v)
	return _u
}

// SetNillableSumLatencyMs sets the "sum_latency_ms" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableSumLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetSumLatencyMs(*v)
	}
	return _u
}

// AddSumLatencyMs adds value to the "sum_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddSumLatencyMs(v)
	return _u
}

// SetCountLatency sets the "count_latency" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetCountLatency(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetCountLatency()
	_u.mutation.SetCountLatency(v)
	return _u
}

// SetNillableCountLatency sets the "count_latency" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableCountLatency(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetCountLatency(*v)
	}
	return _u
}

// AddCountLatency adds value to the "count_latency" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddCountLatency(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddCountLatency(v)
	return _u
}

// SetSumPingLatencyMs sets the "sum_ping_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetSumPingLatencyMs()
	_u.mutation.SetSumPingLatencyMs(v)
	return _u
}

// SetNillableSumPingLatencyMs sets the "sum_ping_latency_ms" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableSumPingLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetSumPingLatencyMs(*v)
	}
	return _u
}

// AddSumPingLatencyMs adds value to the "sum_ping_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddSumPingLatencyMs(v)
	return _u
}

// SetCountPingLatency sets the "count_ping_latency" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetCountPingLatency(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ResetCountPingLatency()
	_u.mutation.SetCountPingLatency(v)
	return _u
}

// SetNillableCountPingLatency sets the "count_ping_latency" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdate) SetNillableCountPingLatency(v *int) *ChannelMonitorDailyRollupUpdate {
	if v != nil {
		_u.SetCountPingLatency(*v)
	}
	return _u
}

// AddCountPingLatency adds value to the "count_ping_latency" field.
func (_u *ChannelMonitorDailyRollupUpdate) AddCountPingLatency(v int) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.AddCountPingLatency(v)
	return _u
}

// SetComputedAt sets the "computed_at" field.
func (_u *ChannelMonitorDailyRollupUpdate) SetComputedAt(v time.Time) *ChannelMonitorDailyRollupUpdate {
	_u.mutation.SetComputedAt(v)
	return _u
}

// SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
func (_u *ChannelMonitorDailyRollupUpdate) SetMonitor(v *ChannelMonitor) *ChannelMonitorDailyRollupUpdate {
	return _u.SetMonitorID(v.ID)
}

// Mutation returns the ChannelMonitorDailyRollupMutation object of the builder.
func (_u *ChannelMonitorDailyRollupUpdate) Mutation() *ChannelMonitorDailyRollupMutation {
	return _u.mutation
}

// ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
func (_u *ChannelMonitorDailyRollupUpdate) ClearMonitor() *ChannelMonitorDailyRollupUpdate {
	_u.mutation.ClearMonitor()
	return _u
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (_u *ChannelMonitorDailyRollupUpdate) defaults() {
	if _, ok := _u.mutation.ComputedAt(); !ok {
		v := channelmonitordailyrollup.UpdateDefaultComputedAt()
		_u.mutation.SetComputedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *ChannelMonitorDailyRollupUpdate) check() error {
	if v, ok := _u.mutation.Model(); ok {
		if err := channelmonitordailyrollup.ModelValidator(v); err != nil {
			return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorDailyRollup.model": %w`, err)}
		}
	}
	if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "ChannelMonitorDailyRollup.monitor"`)
	}
	return nil
}

func (_u *ChannelMonitorDailyRollupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(channelmonitordailyrollup.Table, channelmonitordailyrollup.Columns, sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.Model(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.BucketDate(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldBucketDate, field.TypeTime, value)
	}
	if value, ok := _u.mutation.TotalChecks(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedTotalChecks(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
	}
	if value, ok := _u.mutation.OkCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedOkCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.OperationalCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedOperationalCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.DegradedCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDegradedCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.FailedCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedFailedCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ErrorCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedErrorCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.SumLatencyMs(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSumLatencyMs(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.CountLatency(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCountLatency(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.SumPingLatencyMs(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSumPingLatencyMs(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.CountPingLatency(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCountPingLatency(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ComputedAt(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldComputedAt, field.TypeTime, value)
	}
	if _u.mutation.MonitorCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   channelmonitordailyrollup.MonitorTable,
			Columns: []string{channelmonitordailyrollup.MonitorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   channelmonitordailyrollup.MonitorTable,
			Columns: []string{channelmonitordailyrollup.MonitorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{channelmonitordailyrollup.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// ChannelMonitorDailyRollupUpdateOne is the builder for updating a single ChannelMonitorDailyRollup entity.
type ChannelMonitorDailyRollupUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ChannelMonitorDailyRollupMutation
}

// SetMonitorID sets the "monitor_id" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.SetMonitorID(v)
	return _u
}

// SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableMonitorID(v *int64) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetMonitorID(*v)
	}
	return _u
}

// SetModel sets the "model" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetModel(v string) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.SetModel(v)
	return _u
}

// SetNillableModel sets the "model" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableModel(v *string) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetModel(*v)
	}
	return _u
}

// SetBucketDate sets the "bucket_date" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetBucketDate(v time.Time) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.SetBucketDate(v)
	return _u
}

// SetNillableBucketDate sets the "bucket_date" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableBucketDate(v *time.Time) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetBucketDate(*v)
	}
	return _u
}

// SetTotalChecks sets the "total_checks" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetTotalChecks(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetTotalChecks()
	_u.mutation.SetTotalChecks(v)
	return _u
}

// SetNillableTotalChecks sets the "total_checks" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableTotalChecks(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetTotalChecks(*v)
	}
	return _u
}

// AddTotalChecks adds value to the "total_checks" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddTotalChecks(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddTotalChecks(v)
	return _u
}

// SetOkCount sets the "ok_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetOkCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetOkCount()
	_u.mutation.SetOkCount(v)
	return _u
}

// SetNillableOkCount sets the "ok_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableOkCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetOkCount(*v)
	}
	return _u
}

// AddOkCount adds value to the "ok_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddOkCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddOkCount(v)
	return _u
}

// SetOperationalCount sets the "operational_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetOperationalCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetOperationalCount()
	_u.mutation.SetOperationalCount(v)
	return _u
}

// SetNillableOperationalCount sets the "operational_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableOperationalCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetOperationalCount(*v)
	}
	return _u
}

// AddOperationalCount adds value to the "operational_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddOperationalCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddOperationalCount(v)
	return _u
}

// SetDegradedCount sets the "degraded_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetDegradedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetDegradedCount()
	_u.mutation.SetDegradedCount(v)
	return _u
}

// SetNillableDegradedCount sets the "degraded_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableDegradedCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetDegradedCount(*v)
	}
	return _u
}

// AddDegradedCount adds value to the "degraded_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddDegradedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddDegradedCount(v)
	return _u
}

// SetFailedCount sets the "failed_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetFailedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetFailedCount()
	_u.mutation.SetFailedCount(v)
	return _u
}

// SetNillableFailedCount sets the "failed_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableFailedCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetFailedCount(*v)
	}
	return _u
}

// AddFailedCount adds value to the "failed_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddFailedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddFailedCount(v)
	return _u
}

// SetErrorCount sets the "error_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetErrorCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetErrorCount()
	_u.mutation.SetErrorCount(v)
	return _u
}

// SetNillableErrorCount sets the "error_count" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableErrorCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetErrorCount(*v)
	}
	return _u
}

// AddErrorCount adds value to the "error_count" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddErrorCount(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddErrorCount(v)
	return _u
}

// SetSumLatencyMs sets the "sum_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetSumLatencyMs()
	_u.mutation.SetSumLatencyMs(v)
	return _u
}

// SetNillableSumLatencyMs sets the "sum_latency_ms" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableSumLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetSumLatencyMs(*v)
	}
	return _u
}

// AddSumLatencyMs adds value to the "sum_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddSumLatencyMs(v)
	return _u
}

// SetCountLatency sets the "count_latency" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetCountLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetCountLatency()
	_u.mutation.SetCountLatency(v)
	return _u
}

// SetNillableCountLatency sets the "count_latency" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableCountLatency(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetCountLatency(*v)
	}
	return _u
}

// AddCountLatency adds value to the "count_latency" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddCountLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddCountLatency(v)
	return _u
}

// SetSumPingLatencyMs sets the "sum_ping_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetSumPingLatencyMs()
	_u.mutation.SetSumPingLatencyMs(v)
	return _u
}

// SetNillableSumPingLatencyMs sets the "sum_ping_latency_ms" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableSumPingLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetSumPingLatencyMs(*v)
	}
	return _u
}

// AddSumPingLatencyMs adds value to the "sum_ping_latency_ms" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddSumPingLatencyMs(v)
	return _u
}

// SetCountPingLatency sets the "count_ping_latency" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetCountPingLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ResetCountPingLatency()
	_u.mutation.SetCountPingLatency(v)
	return _u
}

// SetNillableCountPingLatency sets the "count_ping_latency" field if the given value is not nil.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableCountPingLatency(v *int) *ChannelMonitorDailyRollupUpdateOne {
	if v != nil {
		_u.SetCountPingLatency(*v)
	}
	return _u
}

// AddCountPingLatency adds value to the "count_ping_latency" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) AddCountPingLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.AddCountPingLatency(v)
	return _u
}

// SetComputedAt sets the "computed_at" field.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetComputedAt(v time.Time) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.SetComputedAt(v)
	return _u
}

// SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
func (_u *ChannelMonitorDailyRollupUpdateOne) SetMonitor(v *ChannelMonitor) *ChannelMonitorDailyRollupUpdateOne {
	return _u.SetMonitorID(v.ID)
}

// Mutation returns the ChannelMonitorDailyRollupMutation object of the builder.
func (_u *ChannelMonitorDailyRollupUpdateOne) Mutation() *ChannelMonitorDailyRollupMutation {
	return _u.mutation
}

// ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
func (_u *ChannelMonitorDailyRollupUpdateOne) ClearMonitor() *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.ClearMonitor()
	return _u
}

// Where appends a list predicates to the ChannelMonitorDailyRollupUpdate builder.
func (_u *ChannelMonitorDailyRollupUpdateOne) Where(ps ...predicate.ChannelMonitorDailyRollup) *ChannelMonitorDailyRollupUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

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

// Save executes the query and returns the updated ChannelMonitorDailyRollup entity.
func (_u *ChannelMonitorDailyRollupUpdateOne) Save(ctx context.Context) (*ChannelMonitorDailyRollup, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (_u *ChannelMonitorDailyRollupUpdateOne) defaults() {
	if _, ok := _u.mutation.ComputedAt(); !ok {
		v := channelmonitordailyrollup.UpdateDefaultComputedAt()
		_u.mutation.SetComputedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *ChannelMonitorDailyRollupUpdateOne) check() error {
	if v, ok := _u.mutation.Model(); ok {
		if err := channelmonitordailyrollup.ModelValidator(v); err != nil {
			return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorDailyRollup.model": %w`, err)}
		}
	}
	if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "ChannelMonitorDailyRollup.monitor"`)
	}
	return nil
}

func (_u *ChannelMonitorDailyRollupUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitorDailyRollup, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(channelmonitordailyrollup.Table, channelmonitordailyrollup.Columns, sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitorDailyRollup.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, channelmonitordailyrollup.FieldID)
		for _, f := range fields {
			if !channelmonitordailyrollup.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != channelmonitordailyrollup.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.Model(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.BucketDate(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldBucketDate, field.TypeTime, value)
	}
	if value, ok := _u.mutation.TotalChecks(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedTotalChecks(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
	}
	if value, ok := _u.mutation.OkCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedOkCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.OperationalCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedOperationalCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.DegradedCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDegradedCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.FailedCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedFailedCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ErrorCount(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedErrorCount(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.SumLatencyMs(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSumLatencyMs(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.CountLatency(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCountLatency(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.SumPingLatencyMs(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSumPingLatencyMs(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.CountPingLatency(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCountPingLatency(); ok {
		_spec.AddField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ComputedAt(); ok {
		_spec.SetField(channelmonitordailyrollup.FieldComputedAt, field.TypeTime, value)
	}
	if _u.mutation.MonitorCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   channelmonitordailyrollup.MonitorTable,
			Columns: []string{channelmonitordailyrollup.MonitorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   channelmonitordailyrollup.MonitorTable,
			Columns: []string{channelmonitordailyrollup.MonitorColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &ChannelMonitorDailyRollup{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{channelmonitordailyrollup.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
