// Code generated by ent, DO NOT EDIT.

package models

import (
	"encoding/json"
	"fmt"
	"juwan-backend/app/user_verifications/rpc/internal/models/schema"
	"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
	"strings"
	"time"

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

// UserVerifications is the model entity for the UserVerifications schema.
type UserVerifications struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID int64 `json:"user_id,omitempty"`
	// Role holds the value of the "role" field.
	Role string `json:"role,omitempty"`
	// Status holds the value of the "status" field.
	Status string `json:"status,omitempty"`
	// Materials holds the value of the "materials" field.
	Materials schema.MaterialStruct `json:"materials,omitempty"`
	// RejectReason holds the value of the "reject_reason" field.
	RejectReason *string `json:"reject_reason,omitempty"`
	// ReviewedBy holds the value of the "reviewed_by" field.
	ReviewedBy *int64 `json:"reviewed_by,omitempty"`
	// ReviewedAt holds the value of the "reviewed_at" field.
	ReviewedAt *time.Time `json:"reviewed_at,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"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*UserVerifications) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case userverifications.FieldMaterials:
			values[i] = new([]byte)
		case userverifications.FieldID, userverifications.FieldUserID, userverifications.FieldReviewedBy:
			values[i] = new(sql.NullInt64)
		case userverifications.FieldRole, userverifications.FieldStatus, userverifications.FieldRejectReason:
			values[i] = new(sql.NullString)
		case userverifications.FieldReviewedAt, userverifications.FieldCreatedAt, userverifications.FieldUpdatedAt:
			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 UserVerifications fields.
func (_m *UserVerifications) 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 userverifications.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 userverifications.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 userverifications.FieldRole:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field role", values[i])
			} else if value.Valid {
				_m.Role = value.String
			}
		case userverifications.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				_m.Status = value.String
			}
		case userverifications.FieldMaterials:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field materials", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Materials); err != nil {
					return fmt.Errorf("unmarshal field materials: %w", err)
				}
			}
		case userverifications.FieldRejectReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field reject_reason", values[i])
			} else if value.Valid {
				_m.RejectReason = new(string)
				*_m.RejectReason = value.String
			}
		case userverifications.FieldReviewedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field reviewed_by", values[i])
			} else if value.Valid {
				_m.ReviewedBy = new(int64)
				*_m.ReviewedBy = value.Int64
			}
		case userverifications.FieldReviewedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field reviewed_at", values[i])
			} else if value.Valid {
				_m.ReviewedAt = new(time.Time)
				*_m.ReviewedAt = value.Time
			}
		case userverifications.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 userverifications.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
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_m *UserVerifications) String() string {
	var builder strings.Builder
	builder.WriteString("UserVerifications(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.UserID))
	builder.WriteString(", ")
	builder.WriteString("role=")
	builder.WriteString(_m.Role)
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(_m.Status)
	builder.WriteString(", ")
	builder.WriteString("materials=")
	builder.WriteString(fmt.Sprintf("%v", _m.Materials))
	builder.WriteString(", ")
	if v := _m.RejectReason; v != nil {
		builder.WriteString("reject_reason=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.ReviewedBy; v != nil {
		builder.WriteString("reviewed_by=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	if v := _m.ReviewedAt; v != nil {
		builder.WriteString("reviewed_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	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.WriteByte(')')
	return builder.String()
}

// UserVerificationsSlice is a parsable slice of UserVerifications.
type UserVerificationsSlice []*UserVerifications
