// Code generated by ent, DO NOT EDIT.

package ent

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

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

// ApiTag is the model entity for the ApiTag schema.
type ApiTag struct {
	config `json:"-"`
	// ID of the ent.
	ID int32 `json:"id,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Sort holds the value of the "sort" field.
	Sort int32 `json:"sort,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"`
	// UpdateAt holds the value of the "update_at" field.
	UpdateAt time.Time `json:"update_at,omitempty"`
	// UpdateBy holds the value of the "update_by" field.
	UpdateBy uint32 `json:"update_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 (*ApiTag) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case apitag.FieldID, apitag.FieldSort, apitag.FieldCreatedBy, apitag.FieldUpdateBy:
			values[i] = new(sql.NullInt64)
		case apitag.FieldName, apitag.FieldDescription:
			values[i] = new(sql.NullString)
		case apitag.FieldCreatedAt, apitag.FieldUpdateAt:
			values[i] = new(sql.NullTime)
		default:
			return nil, fmt.Errorf("unexpected column %q for type ApiTag", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ApiTag fields.
func (at *ApiTag) 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 apitag.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			at.ID = int32(value.Int64)
		case apitag.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				at.Name = value.String
			}
		case apitag.FieldSort:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field sort", values[i])
			} else if value.Valid {
				at.Sort = int32(value.Int64)
			}
		case apitag.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 {
				at.CreatedAt = value.Time
			}
		case apitag.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 {
				at.CreatedBy = uint32(value.Int64)
			}
		case apitag.FieldUpdateAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field update_at", values[i])
			} else if value.Valid {
				at.UpdateAt = value.Time
			}
		case apitag.FieldUpdateBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field update_by", values[i])
			} else if value.Valid {
				at.UpdateBy = uint32(value.Int64)
			}
		case apitag.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				at.Description = value.String
			}
		}
	}
	return nil
}

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

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

// String implements the fmt.Stringer.
func (at *ApiTag) String() string {
	var builder strings.Builder
	builder.WriteString("ApiTag(")
	builder.WriteString(fmt.Sprintf("id=%v, ", at.ID))
	builder.WriteString("name=")
	builder.WriteString(at.Name)
	builder.WriteString(", ")
	builder.WriteString("sort=")
	builder.WriteString(fmt.Sprintf("%v", at.Sort))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(at.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("created_by=")
	builder.WriteString(fmt.Sprintf("%v", at.CreatedBy))
	builder.WriteString(", ")
	builder.WriteString("update_at=")
	builder.WriteString(at.UpdateAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_by=")
	builder.WriteString(fmt.Sprintf("%v", at.UpdateBy))
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(at.Description)
	builder.WriteByte(')')
	return builder.String()
}

// ApiTags is a parsable slice of ApiTag.
type ApiTags []*ApiTag
