// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/anzhiyu-c/anheyu-app/ent/visitorstat"
)

// VisitorStat is the model entity for the VisitorStat schema.
type VisitorStat struct {
	config `json:"-"`
	// ID of the ent.
	ID uint `json:"id,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// 统计日期（只到天）
	Date time.Time `json:"date,omitempty"`
	// 当日独立访客数
	UniqueVisitors int64 `json:"unique_visitors,omitempty"`
	// 当日总访问量
	TotalViews int64 `json:"total_views,omitempty"`
	// 当日页面浏览量
	PageViews int64 `json:"page_views,omitempty"`
	// 当日跳出次数
	BounceCount  int64 `json:"bounce_count,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*VisitorStat) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case visitorstat.FieldID, visitorstat.FieldUniqueVisitors, visitorstat.FieldTotalViews, visitorstat.FieldPageViews, visitorstat.FieldBounceCount:
			values[i] = new(sql.NullInt64)
		case visitorstat.FieldCreatedAt, visitorstat.FieldUpdatedAt, visitorstat.FieldDate:
			values[i] = new(sql.NullTime)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the VisitorStat fields.
func (_m *VisitorStat) 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 visitorstat.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = uint(value.Int64)
		case visitorstat.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				_m.CreatedAt = value.Time
			}
		case visitorstat.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				_m.UpdatedAt = value.Time
			}
		case visitorstat.FieldDate:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field date", values[i])
			} else if value.Valid {
				_m.Date = value.Time
			}
		case visitorstat.FieldUniqueVisitors:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field unique_visitors", values[i])
			} else if value.Valid {
				_m.UniqueVisitors = value.Int64
			}
		case visitorstat.FieldTotalViews:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total_views", values[i])
			} else if value.Valid {
				_m.TotalViews = value.Int64
			}
		case visitorstat.FieldPageViews:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field page_views", values[i])
			} else if value.Valid {
				_m.PageViews = value.Int64
			}
		case visitorstat.FieldBounceCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field bounce_count", values[i])
			} else if value.Valid {
				_m.BounceCount = value.Int64
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

// Unwrap unwraps the VisitorStat 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 (_m *VisitorStat) Unwrap() *VisitorStat {
	_tx, ok := _m.config.driver.(*txDriver)
	if !ok {
		panic("ent: VisitorStat is not a transactional entity")
	}
	_m.config.driver = _tx.drv
	return _m
}

// String implements the fmt.Stringer.
func (_m *VisitorStat) String() string {
	var builder strings.Builder
	builder.WriteString("VisitorStat(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("date=")
	builder.WriteString(_m.Date.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("unique_visitors=")
	builder.WriteString(fmt.Sprintf("%v", _m.UniqueVisitors))
	builder.WriteString(", ")
	builder.WriteString("total_views=")
	builder.WriteString(fmt.Sprintf("%v", _m.TotalViews))
	builder.WriteString(", ")
	builder.WriteString("page_views=")
	builder.WriteString(fmt.Sprintf("%v", _m.PageViews))
	builder.WriteString(", ")
	builder.WriteString("bounce_count=")
	builder.WriteString(fmt.Sprintf("%v", _m.BounceCount))
	builder.WriteByte(')')
	return builder.String()
}

// VisitorStats is a parsable slice of VisitorStat.
type VisitorStats []*VisitorStat
