// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
)

// MetaEvent is the model entity for the MetaEvent schema.
type MetaEvent struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// EventName holds the value of the "event_name" field.
	EventName string `json:"event_name,omitempty"`
	// 通用唯一识别码
	UUID uuid.UUID `json:"uuid,omitempty"`
	// DisplayName holds the value of the "display_name" field.
	DisplayName string `json:"display_name,omitempty"`
	// EventDesc holds the value of the "event_desc" field.
	EventDesc string `json:"event_desc,omitempty"`
	// Remark holds the value of the "remark" field.
	Remark string `json:"remark,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"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*MetaEvent) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case metaevent.FieldID:
			values[i] = new(sql.NullInt64)
		case metaevent.FieldEventName, metaevent.FieldDisplayName, metaevent.FieldEventDesc, metaevent.FieldRemark:
			values[i] = new(sql.NullString)
		case metaevent.FieldCreatedAt, metaevent.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		case metaevent.FieldUUID:
			values[i] = new(uuid.UUID)
		default:
			return nil, fmt.Errorf("unexpected column %q for type MetaEvent", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the MetaEvent fields.
func (me *MetaEvent) 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 metaevent.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			me.ID = int64(value.Int64)
		case metaevent.FieldEventName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field event_name", values[i])
			} else if value.Valid {
				me.EventName = value.String
			}
		case metaevent.FieldUUID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field uuid", values[i])
			} else if value != nil {
				me.UUID = *value
			}
		case metaevent.FieldDisplayName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field display_name", values[i])
			} else if value.Valid {
				me.DisplayName = value.String
			}
		case metaevent.FieldEventDesc:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field event_desc", values[i])
			} else if value.Valid {
				me.EventDesc = value.String
			}
		case metaevent.FieldRemark:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field remark", values[i])
			} else if value.Valid {
				me.Remark = value.String
			}
		case metaevent.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 {
				me.CreatedAt = value.Time
			}
		case metaevent.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 {
				me.UpdatedAt = value.Time
			}
		}
	}
	return nil
}

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

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

// String implements the fmt.Stringer.
func (me *MetaEvent) String() string {
	var builder strings.Builder
	builder.WriteString("MetaEvent(")
	builder.WriteString(fmt.Sprintf("id=%v, ", me.ID))
	builder.WriteString("event_name=")
	builder.WriteString(me.EventName)
	builder.WriteString(", ")
	builder.WriteString("uuid=")
	builder.WriteString(fmt.Sprintf("%v", me.UUID))
	builder.WriteString(", ")
	builder.WriteString("display_name=")
	builder.WriteString(me.DisplayName)
	builder.WriteString(", ")
	builder.WriteString("event_desc=")
	builder.WriteString(me.EventDesc)
	builder.WriteString(", ")
	builder.WriteString("remark=")
	builder.WriteString(me.Remark)
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(me.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(me.UpdatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// MetaEvents is a parsable slice of MetaEvent.
type MetaEvents []*MetaEvent
