// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"galileo/ent/apihistory"
	"strings"
	"time"

	"entgo.io/ent/dialect/sql"
)

// ApiHistory is the model entity for the ApiHistory schema.
type ApiHistory struct {
	config `json:"-"`
	// ID of the ent.
	ID int32 `json:"id,omitempty"`
	// Version holds the value of the "version" field.
	Version int32 `json:"version,omitempty"`
	// QueryParams holds the value of the "query_params" field.
	QueryParams string `json:"query_params,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// CreatedBy holds the value of the "created_by" field.
	CreatedBy uint32 `json:"created_by,omitempty"`
	// Description holds the value of the "description" field.
	Description string `json:"description,omitempty"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*ApiHistory) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case apihistory.FieldID, apihistory.FieldVersion, apihistory.FieldCreatedBy:
			values[i] = new(sql.NullInt64)
		case apihistory.FieldQueryParams, apihistory.FieldDescription:
			values[i] = new(sql.NullString)
		case apihistory.FieldCreatedAt:
			values[i] = new(sql.NullTime)
		default:
			return nil, fmt.Errorf("unexpected column %q for type ApiHistory", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ApiHistory fields.
func (ah *ApiHistory) 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 apihistory.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			ah.ID = int32(value.Int64)
		case apihistory.FieldVersion:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field version", values[i])
			} else if value.Valid {
				ah.Version = int32(value.Int64)
			}
		case apihistory.FieldQueryParams:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field query_params", values[i])
			} else if value.Valid {
				ah.QueryParams = value.String
			}
		case apihistory.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 {
				ah.CreatedAt = value.Time
			}
		case apihistory.FieldCreatedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field created_by", values[i])
			} else if value.Valid {
				ah.CreatedBy = uint32(value.Int64)
			}
		case apihistory.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				ah.Description = value.String
			}
		}
	}
	return nil
}

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

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

// String implements the fmt.Stringer.
func (ah *ApiHistory) String() string {
	var builder strings.Builder
	builder.WriteString("ApiHistory(")
	builder.WriteString(fmt.Sprintf("id=%v, ", ah.ID))
	builder.WriteString("version=")
	builder.WriteString(fmt.Sprintf("%v", ah.Version))
	builder.WriteString(", ")
	builder.WriteString("query_params=")
	builder.WriteString(ah.QueryParams)
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(ah.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("created_by=")
	builder.WriteString(fmt.Sprintf("%v", ah.CreatedBy))
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(ah.Description)
	builder.WriteByte(')')
	return builder.String()
}

// ApiHistories is a parsable slice of ApiHistory.
type ApiHistories []*ApiHistory
