// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

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

// EventFile is the model entity for the EventFile schema.
type EventFile struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// URL holds the value of the "url" field.
	URL string `json:"url,omitempty"`
	// ModTime holds the value of the "mod_time" field.
	ModTime time.Time `json:"mod_time,omitempty"`
	// Protocol holds the value of the "protocol" field.
	Protocol string `json:"protocol,omitempty"`
	// MimeType holds the value of the "mime_type" field.
	MimeType string `json:"mime_type,omitempty"`
	// Status holds the value of the "status" field.
	Status string `json:"status,omitempty"`
	// Reason holds the value of the "reason" field.
	Reason string `json:"reason,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the EventFileQuery when eager-loading is set.
	Edges        EventFileEdges `json:"edges"`
	selectValues sql.SelectValues
}

// EventFileEdges holds the relations/edges for other nodes in the graph.
type EventFileEdges struct {
	// BazelInvocation holds the value of the bazel_invocation edge.
	BazelInvocation *BazelInvocation `json:"bazel_invocation,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
}

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

// scanValues returns the types for scanning values from sql.Rows.
func (*EventFile) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case eventfile.FieldID:
			values[i] = new(sql.NullInt64)
		case eventfile.FieldURL, eventfile.FieldProtocol, eventfile.FieldMimeType, eventfile.FieldStatus, eventfile.FieldReason:
			values[i] = new(sql.NullString)
		case eventfile.FieldModTime:
			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 EventFile fields.
func (ef *EventFile) 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 eventfile.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			ef.ID = int(value.Int64)
		case eventfile.FieldURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field url", values[i])
			} else if value.Valid {
				ef.URL = value.String
			}
		case eventfile.FieldModTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field mod_time", values[i])
			} else if value.Valid {
				ef.ModTime = value.Time
			}
		case eventfile.FieldProtocol:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field protocol", values[i])
			} else if value.Valid {
				ef.Protocol = value.String
			}
		case eventfile.FieldMimeType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field mime_type", values[i])
			} else if value.Valid {
				ef.MimeType = value.String
			}
		case eventfile.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				ef.Status = value.String
			}
		case eventfile.FieldReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field reason", values[i])
			} else if value.Valid {
				ef.Reason = value.String
			}
		default:
			ef.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryBazelInvocation queries the "bazel_invocation" edge of the EventFile entity.
func (ef *EventFile) QueryBazelInvocation() *BazelInvocationQuery {
	return NewEventFileClient(ef.config).QueryBazelInvocation(ef)
}

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

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

// String implements the fmt.Stringer.
func (ef *EventFile) String() string {
	var builder strings.Builder
	builder.WriteString("EventFile(")
	builder.WriteString(fmt.Sprintf("id=%v, ", ef.ID))
	builder.WriteString("url=")
	builder.WriteString(ef.URL)
	builder.WriteString(", ")
	builder.WriteString("mod_time=")
	builder.WriteString(ef.ModTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("protocol=")
	builder.WriteString(ef.Protocol)
	builder.WriteString(", ")
	builder.WriteString("mime_type=")
	builder.WriteString(ef.MimeType)
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(ef.Status)
	builder.WriteString(", ")
	builder.WriteString("reason=")
	builder.WriteString(ef.Reason)
	builder.WriteByte(')')
	return builder.String()
}

// EventFiles is a parsable slice of EventFile.
type EventFiles []*EventFile
