// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/cloudreve/Cloudreve/v4/ent/fsevent"
	"github.com/cloudreve/Cloudreve/v4/ent/user"
	"github.com/gofrs/uuid"
)

// FsEvent is the model entity for the FsEvent schema.
type FsEvent struct {
	config `json:"-"`
	// ID of the ent.
	ID int `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"`
	// DeletedAt holds the value of the "deleted_at" field.
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	// Event holds the value of the "event" field.
	Event string `json:"event,omitempty"`
	// Subscriber holds the value of the "subscriber" field.
	Subscriber uuid.UUID `json:"subscriber,omitempty"`
	// UserFsevent holds the value of the "user_fsevent" field.
	UserFsevent int `json:"user_fsevent,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the FsEventQuery when eager-loading is set.
	Edges        FsEventEdges `json:"edges"`
	selectValues sql.SelectValues
}

// FsEventEdges holds the relations/edges for other nodes in the graph.
type FsEventEdges struct {
	// User holds the value of the user edge.
	User *User `json:"user,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
}

// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e FsEventEdges) UserOrErr() (*User, error) {
	if e.loadedTypes[0] {
		if e.User == nil {
			// Edge was loaded but was not found.
			return nil, &NotFoundError{label: user.Label}
		}
		return e.User, nil
	}
	return nil, &NotLoadedError{edge: "user"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*FsEvent) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case fsevent.FieldID, fsevent.FieldUserFsevent:
			values[i] = new(sql.NullInt64)
		case fsevent.FieldEvent:
			values[i] = new(sql.NullString)
		case fsevent.FieldCreatedAt, fsevent.FieldUpdatedAt, fsevent.FieldDeletedAt:
			values[i] = new(sql.NullTime)
		case fsevent.FieldSubscriber:
			values[i] = new(uuid.UUID)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the FsEvent fields.
func (fe *FsEvent) 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 fsevent.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			fe.ID = int(value.Int64)
		case fsevent.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 {
				fe.CreatedAt = value.Time
			}
		case fsevent.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 {
				fe.UpdatedAt = value.Time
			}
		case fsevent.FieldDeletedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
			} else if value.Valid {
				fe.DeletedAt = new(time.Time)
				*fe.DeletedAt = value.Time
			}
		case fsevent.FieldEvent:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field event", values[i])
			} else if value.Valid {
				fe.Event = value.String
			}
		case fsevent.FieldSubscriber:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field subscriber", values[i])
			} else if value != nil {
				fe.Subscriber = *value
			}
		case fsevent.FieldUserFsevent:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field user_fsevent", values[i])
			} else if value.Valid {
				fe.UserFsevent = int(value.Int64)
			}
		default:
			fe.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryUser queries the "user" edge of the FsEvent entity.
func (fe *FsEvent) QueryUser() *UserQuery {
	return NewFsEventClient(fe.config).QueryUser(fe)
}

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

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

// String implements the fmt.Stringer.
func (fe *FsEvent) String() string {
	var builder strings.Builder
	builder.WriteString("FsEvent(")
	builder.WriteString(fmt.Sprintf("id=%v, ", fe.ID))
	builder.WriteString("created_at=")
	builder.WriteString(fe.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(fe.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	if v := fe.DeletedAt; v != nil {
		builder.WriteString("deleted_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	builder.WriteString("event=")
	builder.WriteString(fe.Event)
	builder.WriteString(", ")
	builder.WriteString("subscriber=")
	builder.WriteString(fmt.Sprintf("%v", fe.Subscriber))
	builder.WriteString(", ")
	builder.WriteString("user_fsevent=")
	builder.WriteString(fmt.Sprintf("%v", fe.UserFsevent))
	builder.WriteByte(')')
	return builder.String()
}

// SetUser manually set the edge as loaded state.
func (e *FsEvent) SetUser(v *User) {
	e.Edges.User = v
	e.Edges.loadedTypes[0] = true
}

// FsEvents is a parsable slice of FsEvent.
type FsEvents []*FsEvent
