// Code generated by ent, DO NOT EDIT.

package ent

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
	"github.com/lightsparkdev/spark/so/ent/gossip"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
)

// Gossip is the model entity for the Gossip schema.
type Gossip struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// CreateTime holds the value of the "create_time" field.
	CreateTime time.Time `json:"create_time,omitempty"`
	// UpdateTime holds the value of the "update_time" field.
	UpdateTime time.Time `json:"update_time,omitempty"`
	// Participants holds the value of the "participants" field.
	Participants []string `json:"participants,omitempty"`
	// Message holds the value of the "message" field.
	Message []byte `json:"message,omitempty"`
	// Receipts holds the value of the "receipts" field.
	Receipts *[]byte `json:"receipts,omitempty"`
	// Status holds the value of the "status" field.
	Status       schematype.GossipStatus `json:"status,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Gossip) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case gossip.FieldParticipants, gossip.FieldMessage, gossip.FieldReceipts:
			values[i] = new([]byte)
		case gossip.FieldStatus:
			values[i] = new(sql.NullString)
		case gossip.FieldCreateTime, gossip.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case gossip.FieldID:
			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 Gossip fields.
func (_go *Gossip) 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 gossip.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				_go.ID = *value
			}
		case gossip.FieldCreateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field create_time", values[i])
			} else if value.Valid {
				_go.CreateTime = value.Time
			}
		case gossip.FieldUpdateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field update_time", values[i])
			} else if value.Valid {
				_go.UpdateTime = value.Time
			}
		case gossip.FieldParticipants:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field participants", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_go.Participants); err != nil {
					return fmt.Errorf("unmarshal field participants: %w", err)
				}
			}
		case gossip.FieldMessage:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field message", values[i])
			} else if value != nil {
				_go.Message = *value
			}
		case gossip.FieldReceipts:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field receipts", values[i])
			} else if value != nil {
				_go.Receipts = value
			}
		case gossip.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				_go.Status = schematype.GossipStatus(value.String)
			}
		default:
			_go.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_go *Gossip) String() string {
	var builder strings.Builder
	builder.WriteString("Gossip(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _go.ID))
	builder.WriteString("create_time=")
	builder.WriteString(_go.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(_go.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("participants=")
	builder.WriteString(fmt.Sprintf("%v", _go.Participants))
	builder.WriteString(", ")
	builder.WriteString("message=")
	builder.WriteString(fmt.Sprintf("%v", _go.Message))
	builder.WriteString(", ")
	if v := _go.Receipts; v != nil {
		builder.WriteString("receipts=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", _go.Status))
	builder.WriteByte(')')
	return builder.String()
}

// Gossips is a parsable slice of Gossip.
type Gossips []*Gossip
