// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/Wei-Shaw/sub2api/ent/requestcapturelog"
)

// RequestCaptureLog is the model entity for the RequestCaptureLog schema.
type RequestCaptureLog struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// APIKeyID holds the value of the "api_key_id" field.
	APIKeyID int64 `json:"api_key_id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID int64 `json:"user_id,omitempty"`
	// RequestID holds the value of the "request_id" field.
	RequestID *string `json:"request_id,omitempty"`
	// Path holds the value of the "path" field.
	Path *string `json:"path,omitempty"`
	// Method holds the value of the "method" field.
	Method *string `json:"method,omitempty"`
	// IPAddress holds the value of the "ip_address" field.
	IPAddress *string `json:"ip_address,omitempty"`
	// RequestBody holds the value of the "request_body" field.
	RequestBody *string `json:"request_body,omitempty"`
	// ResponseBody holds the value of the "response_body" field.
	ResponseBody *string `json:"response_body,omitempty"`
	// NfsFilePath holds the value of the "nfs_file_path" field.
	NfsFilePath *string `json:"nfs_file_path,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt    time.Time `json:"created_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*RequestCaptureLog) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case requestcapturelog.FieldID, requestcapturelog.FieldAPIKeyID, requestcapturelog.FieldUserID:
			values[i] = new(sql.NullInt64)
		case requestcapturelog.FieldRequestID, requestcapturelog.FieldPath, requestcapturelog.FieldMethod, requestcapturelog.FieldIPAddress, requestcapturelog.FieldRequestBody, requestcapturelog.FieldResponseBody, requestcapturelog.FieldNfsFilePath:
			values[i] = new(sql.NullString)
		case requestcapturelog.FieldCreatedAt:
			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 RequestCaptureLog fields.
func (_m *RequestCaptureLog) 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 requestcapturelog.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int64(value.Int64)
		case requestcapturelog.FieldAPIKeyID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field api_key_id", values[i])
			} else if value.Valid {
				_m.APIKeyID = value.Int64
			}
		case requestcapturelog.FieldUserID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field user_id", values[i])
			} else if value.Valid {
				_m.UserID = value.Int64
			}
		case requestcapturelog.FieldRequestID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field request_id", values[i])
			} else if value.Valid {
				_m.RequestID = new(string)
				*_m.RequestID = value.String
			}
		case requestcapturelog.FieldPath:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field path", values[i])
			} else if value.Valid {
				_m.Path = new(string)
				*_m.Path = value.String
			}
		case requestcapturelog.FieldMethod:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field method", values[i])
			} else if value.Valid {
				_m.Method = new(string)
				*_m.Method = value.String
			}
		case requestcapturelog.FieldIPAddress:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field ip_address", values[i])
			} else if value.Valid {
				_m.IPAddress = new(string)
				*_m.IPAddress = value.String
			}
		case requestcapturelog.FieldRequestBody:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field request_body", values[i])
			} else if value.Valid {
				_m.RequestBody = new(string)
				*_m.RequestBody = value.String
			}
		case requestcapturelog.FieldResponseBody:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field response_body", values[i])
			} else if value.Valid {
				_m.ResponseBody = new(string)
				*_m.ResponseBody = value.String
			}
		case requestcapturelog.FieldNfsFilePath:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field nfs_file_path", values[i])
			} else if value.Valid {
				_m.NfsFilePath = new(string)
				*_m.NfsFilePath = value.String
			}
		case requestcapturelog.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
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_m *RequestCaptureLog) String() string {
	var builder strings.Builder
	builder.WriteString("RequestCaptureLog(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("api_key_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.APIKeyID))
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.UserID))
	builder.WriteString(", ")
	if v := _m.RequestID; v != nil {
		builder.WriteString("request_id=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.Path; v != nil {
		builder.WriteString("path=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.Method; v != nil {
		builder.WriteString("method=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.IPAddress; v != nil {
		builder.WriteString("ip_address=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.RequestBody; v != nil {
		builder.WriteString("request_body=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.ResponseBody; v != nil {
		builder.WriteString("response_body=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.NfsFilePath; v != nil {
		builder.WriteString("nfs_file_path=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// RequestCaptureLogs is a parsable slice of RequestCaptureLog.
type RequestCaptureLogs []*RequestCaptureLog
