// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"registry-backend/ent/personalaccesstoken"
	"registry-backend/ent/publisher"
	"strings"
	"time"

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

// PersonalAccessToken is the model entity for the PersonalAccessToken schema.
type PersonalAccessToken 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"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Description holds the value of the "description" field.
	Description string `json:"description,omitempty"`
	// PublisherID holds the value of the "publisher_id" field.
	PublisherID string `json:"publisher_id,omitempty"`
	// Token holds the value of the "token" field.
	Token string `json:"-"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the PersonalAccessTokenQuery when eager-loading is set.
	Edges        PersonalAccessTokenEdges `json:"edges"`
	selectValues sql.SelectValues
}

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

// PublisherOrErr returns the Publisher value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PersonalAccessTokenEdges) PublisherOrErr() (*Publisher, error) {
	if e.Publisher != nil {
		return e.Publisher, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: publisher.Label}
	}
	return nil, &NotLoadedError{edge: "publisher"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*PersonalAccessToken) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case personalaccesstoken.FieldName, personalaccesstoken.FieldDescription, personalaccesstoken.FieldPublisherID, personalaccesstoken.FieldToken:
			values[i] = new(sql.NullString)
		case personalaccesstoken.FieldCreateTime, personalaccesstoken.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case personalaccesstoken.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 PersonalAccessToken fields.
func (pat *PersonalAccessToken) 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 personalaccesstoken.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				pat.ID = *value
			}
		case personalaccesstoken.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 {
				pat.CreateTime = value.Time
			}
		case personalaccesstoken.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 {
				pat.UpdateTime = value.Time
			}
		case personalaccesstoken.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				pat.Name = value.String
			}
		case personalaccesstoken.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				pat.Description = value.String
			}
		case personalaccesstoken.FieldPublisherID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field publisher_id", values[i])
			} else if value.Valid {
				pat.PublisherID = value.String
			}
		case personalaccesstoken.FieldToken:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field token", values[i])
			} else if value.Valid {
				pat.Token = value.String
			}
		default:
			pat.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryPublisher queries the "publisher" edge of the PersonalAccessToken entity.
func (pat *PersonalAccessToken) QueryPublisher() *PublisherQuery {
	return NewPersonalAccessTokenClient(pat.config).QueryPublisher(pat)
}

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

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

// String implements the fmt.Stringer.
func (pat *PersonalAccessToken) String() string {
	var builder strings.Builder
	builder.WriteString("PersonalAccessToken(")
	builder.WriteString(fmt.Sprintf("id=%v, ", pat.ID))
	builder.WriteString("create_time=")
	builder.WriteString(pat.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(pat.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(pat.Name)
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(pat.Description)
	builder.WriteString(", ")
	builder.WriteString("publisher_id=")
	builder.WriteString(pat.PublisherID)
	builder.WriteString(", ")
	builder.WriteString("token=<sensitive>")
	builder.WriteByte(')')
	return builder.String()
}

// PersonalAccessTokens is a parsable slice of PersonalAccessToken.
type PersonalAccessTokens []*PersonalAccessToken
