// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/anzhiyu-c/anheyu-app/ent/linktag"
)

// LinkTag is the model entity for the LinkTag schema.
type LinkTag struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// 标签名称
	Name string `json:"name,omitempty"`
	// 标签颜色 (e.g., #ff0000)
	Color string `json:"color,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the LinkTagQuery when eager-loading is set.
	Edges        LinkTagEdges `json:"edges"`
	selectValues sql.SelectValues
}

// LinkTagEdges holds the relations/edges for other nodes in the graph.
type LinkTagEdges struct {
	// Links holds the value of the links edge.
	Links []*Link `json:"links,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
}

// LinksOrErr returns the Links value or an error if the edge
// was not loaded in eager-loading.
func (e LinkTagEdges) LinksOrErr() ([]*Link, error) {
	if e.loadedTypes[0] {
		return e.Links, nil
	}
	return nil, &NotLoadedError{edge: "links"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*LinkTag) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case linktag.FieldID:
			values[i] = new(sql.NullInt64)
		case linktag.FieldName, linktag.FieldColor:
			values[i] = new(sql.NullString)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the LinkTag fields.
func (_m *LinkTag) 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 linktag.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int(value.Int64)
		case linktag.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				_m.Name = value.String
			}
		case linktag.FieldColor:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field color", values[i])
			} else if value.Valid {
				_m.Color = value.String
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryLinks queries the "links" edge of the LinkTag entity.
func (_m *LinkTag) QueryLinks() *LinkQuery {
	return NewLinkTagClient(_m.config).QueryLinks(_m)
}

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

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

// String implements the fmt.Stringer.
func (_m *LinkTag) String() string {
	var builder strings.Builder
	builder.WriteString("LinkTag(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("name=")
	builder.WriteString(_m.Name)
	builder.WriteString(", ")
	builder.WriteString("color=")
	builder.WriteString(_m.Color)
	builder.WriteByte(')')
	return builder.String()
}

// LinkTags is a parsable slice of LinkTag.
type LinkTags []*LinkTag
