// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"

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

// SystemNetworkStats is the model entity for the SystemNetworkStats schema.
type SystemNetworkStats struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// BytesSent holds the value of the "bytes_sent" field.
	BytesSent uint64 `json:"bytes_sent,omitempty"`
	// BytesRecv holds the value of the "bytes_recv" field.
	BytesRecv uint64 `json:"bytes_recv,omitempty"`
	// PacketsSent holds the value of the "packets_sent" field.
	PacketsSent uint64 `json:"packets_sent,omitempty"`
	// PacketsRecv holds the value of the "packets_recv" field.
	PacketsRecv uint64 `json:"packets_recv,omitempty"`
	// PeakBytesSentPerSec holds the value of the "peak_bytes_sent_per_sec" field.
	PeakBytesSentPerSec uint64 `json:"peak_bytes_sent_per_sec,omitempty"`
	// PeakBytesRecvPerSec holds the value of the "peak_bytes_recv_per_sec" field.
	PeakBytesRecvPerSec uint64 `json:"peak_bytes_recv_per_sec,omitempty"`
	// PeakPacketsSentPerSec holds the value of the "peak_packets_sent_per_sec" field.
	PeakPacketsSentPerSec uint64 `json:"peak_packets_sent_per_sec,omitempty"`
	// PeakPacketsRecvPerSec holds the value of the "peak_packets_recv_per_sec" field.
	PeakPacketsRecvPerSec uint64 `json:"peak_packets_recv_per_sec,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the SystemNetworkStatsQuery when eager-loading is set.
	Edges                                SystemNetworkStatsEdges `json:"edges"`
	network_metrics_system_network_stats *int
	selectValues                         sql.SelectValues
}

// SystemNetworkStatsEdges holds the relations/edges for other nodes in the graph.
type SystemNetworkStatsEdges struct {
	// NetworkMetrics holds the value of the network_metrics edge.
	NetworkMetrics *NetworkMetrics `json:"network_metrics,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
	// totalCount holds the count of the edges above.
	totalCount [1]map[string]int
}

// NetworkMetricsOrErr returns the NetworkMetrics value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SystemNetworkStatsEdges) NetworkMetricsOrErr() (*NetworkMetrics, error) {
	if e.NetworkMetrics != nil {
		return e.NetworkMetrics, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: networkmetrics.Label}
	}
	return nil, &NotLoadedError{edge: "network_metrics"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*SystemNetworkStats) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case systemnetworkstats.FieldID, systemnetworkstats.FieldBytesSent, systemnetworkstats.FieldBytesRecv, systemnetworkstats.FieldPacketsSent, systemnetworkstats.FieldPacketsRecv, systemnetworkstats.FieldPeakBytesSentPerSec, systemnetworkstats.FieldPeakBytesRecvPerSec, systemnetworkstats.FieldPeakPacketsSentPerSec, systemnetworkstats.FieldPeakPacketsRecvPerSec:
			values[i] = new(sql.NullInt64)
		case systemnetworkstats.ForeignKeys[0]: // network_metrics_system_network_stats
			values[i] = new(sql.NullInt64)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the SystemNetworkStats fields.
func (sns *SystemNetworkStats) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case systemnetworkstats.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			sns.ID = int(value.Int64)
		case systemnetworkstats.FieldBytesSent:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field bytes_sent", values[i])
			} else if value.Valid {
				sns.BytesSent = uint64(value.Int64)
			}
		case systemnetworkstats.FieldBytesRecv:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field bytes_recv", values[i])
			} else if value.Valid {
				sns.BytesRecv = uint64(value.Int64)
			}
		case systemnetworkstats.FieldPacketsSent:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field packets_sent", values[i])
			} else if value.Valid {
				sns.PacketsSent = uint64(value.Int64)
			}
		case systemnetworkstats.FieldPacketsRecv:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field packets_recv", values[i])
			} else if value.Valid {
				sns.PacketsRecv = uint64(value.Int64)
			}
		case systemnetworkstats.FieldPeakBytesSentPerSec:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field peak_bytes_sent_per_sec", values[i])
			} else if value.Valid {
				sns.PeakBytesSentPerSec = uint64(value.Int64)
			}
		case systemnetworkstats.FieldPeakBytesRecvPerSec:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field peak_bytes_recv_per_sec", values[i])
			} else if value.Valid {
				sns.PeakBytesRecvPerSec = uint64(value.Int64)
			}
		case systemnetworkstats.FieldPeakPacketsSentPerSec:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field peak_packets_sent_per_sec", values[i])
			} else if value.Valid {
				sns.PeakPacketsSentPerSec = uint64(value.Int64)
			}
		case systemnetworkstats.FieldPeakPacketsRecvPerSec:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field peak_packets_recv_per_sec", values[i])
			} else if value.Valid {
				sns.PeakPacketsRecvPerSec = uint64(value.Int64)
			}
		case systemnetworkstats.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for edge-field network_metrics_system_network_stats", value)
			} else if value.Valid {
				sns.network_metrics_system_network_stats = new(int)
				*sns.network_metrics_system_network_stats = int(value.Int64)
			}
		default:
			sns.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the SystemNetworkStats.
// This includes values selected through modifiers, order, etc.
func (sns *SystemNetworkStats) Value(name string) (ent.Value, error) {
	return sns.selectValues.Get(name)
}

// QueryNetworkMetrics queries the "network_metrics" edge of the SystemNetworkStats entity.
func (sns *SystemNetworkStats) QueryNetworkMetrics() *NetworkMetricsQuery {
	return NewSystemNetworkStatsClient(sns.config).QueryNetworkMetrics(sns)
}

// Update returns a builder for updating this SystemNetworkStats.
// Note that you need to call SystemNetworkStats.Unwrap() before calling this method if this SystemNetworkStats
// was returned from a transaction, and the transaction was committed or rolled back.
func (sns *SystemNetworkStats) Update() *SystemNetworkStatsUpdateOne {
	return NewSystemNetworkStatsClient(sns.config).UpdateOne(sns)
}

// Unwrap unwraps the SystemNetworkStats entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (sns *SystemNetworkStats) Unwrap() *SystemNetworkStats {
	_tx, ok := sns.config.driver.(*txDriver)
	if !ok {
		panic("ent: SystemNetworkStats is not a transactional entity")
	}
	sns.config.driver = _tx.drv
	return sns
}

// String implements the fmt.Stringer.
func (sns *SystemNetworkStats) String() string {
	var builder strings.Builder
	builder.WriteString("SystemNetworkStats(")
	builder.WriteString(fmt.Sprintf("id=%v, ", sns.ID))
	builder.WriteString("bytes_sent=")
	builder.WriteString(fmt.Sprintf("%v", sns.BytesSent))
	builder.WriteString(", ")
	builder.WriteString("bytes_recv=")
	builder.WriteString(fmt.Sprintf("%v", sns.BytesRecv))
	builder.WriteString(", ")
	builder.WriteString("packets_sent=")
	builder.WriteString(fmt.Sprintf("%v", sns.PacketsSent))
	builder.WriteString(", ")
	builder.WriteString("packets_recv=")
	builder.WriteString(fmt.Sprintf("%v", sns.PacketsRecv))
	builder.WriteString(", ")
	builder.WriteString("peak_bytes_sent_per_sec=")
	builder.WriteString(fmt.Sprintf("%v", sns.PeakBytesSentPerSec))
	builder.WriteString(", ")
	builder.WriteString("peak_bytes_recv_per_sec=")
	builder.WriteString(fmt.Sprintf("%v", sns.PeakBytesRecvPerSec))
	builder.WriteString(", ")
	builder.WriteString("peak_packets_sent_per_sec=")
	builder.WriteString(fmt.Sprintf("%v", sns.PeakPacketsSentPerSec))
	builder.WriteString(", ")
	builder.WriteString("peak_packets_recv_per_sec=")
	builder.WriteString(fmt.Sprintf("%v", sns.PeakPacketsRecvPerSec))
	builder.WriteByte(')')
	return builder.String()
}

// SystemNetworkStatsSlice is a parsable slice of SystemNetworkStats.
type SystemNetworkStatsSlice []*SystemNetworkStats
